I am developing a wrapper for a third party function library that is interfacing with some special hardware. So basically, I want to encapsulate the dll functions (bool Connect()
, void Disconnect()
etc) in a MyHardwareObject with connect- and disconnect methods.
The Connect function from the dll can throw some specific exceptions, for example when the hardware is not present. For the application, the information on why the connect method failed is considered unimportant, so the additional information contained in the exception is not needed.
What is the best way of handling those exceptions, returning false
, or leaving the exception unhandled here and catch it on the level that would otherwise handle the fact that the connect method returnded false
?
bool MyHardwareObject.Connect()
{
try
{
ThirdPartyLibrary.Connect();
}
catch (SomeException)
{
return false;
}
return true;
}
As opposed to
bool MyHardwareObject.Connect()
{
ThirdPartyLibrary.Connect();
return true;
}
(or in the second case better void MyHardwareObject.Connect()
, since we either return true, or throw an exception?)
Or what else would you do? And most important: Why?