Is there a best-practice or industry standard for throwing exceptions from a toolkit API?
Should the user facing methods catch and wrap up Exception
in some sort of CustomException
so that users only have to worry about CustomException
s coming out of the API?
Or is the convention to just let those bubble up?
We're concerned with being able to document all possible exceptions our API methods might throw. (e.g. if our API method calls, Stream.Write()
which throws 4 or 5 exceptions we'd have to document all of those plus other exceptions other called methods might throw)
We were thinking of doing something like this
public void customerFacingApiMethod(){
try {
//api functionality goes here
} catch (Exception e) {
throw new CustomException(e);
}
}