Should I put multiple statements in a try and then catch all possible exceptions, or should I put only one statement in the try statement?
Example:
If they are truly separate like that, then the first is better practice, simply because it's shorter.
However, if it's possible for MaybeThrowIOException()
to throw a FooBarException
, or for MaybeThrowFooBarException()
to throw a IOException
, then you should only wrap them together if you want them both to take the same action upon an exception!