Hi,
the most important part is to document that your module/class/object may throw an exception and to explain under what condition this happens. In my opinion there are two main classes of exceptions: Runtime exceptions which are most of the time not recoverable (but probably sometimes with a retry) and exceptions caused by a module usage which is not allowed. I'm not a friend of an exception being a regular "output" of a method/function.
So, my (absolute personal) rule of thumb is: When you use a function/method in the intended way in a "working" runtime environment you shouldn't get an exception.
In your case: When you know as a caller of the class that you often will run into an exception situation it is valid to wrap all with an eval (better Try::Tiny) or check the invalid usage before calling the function/method.
Regards
McA
In reply to Re: Croak, return et al.
by McA
in thread Croak, return et al.
by packetstormer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |