in reply to Croak, return et al.

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

Replies are listed 'Best First'.
Re^2: Croak, return et al.
by packetstormer (Monk) on Aug 16, 2014 at 18:22 UTC

    Thanks for the replies! It seems to confirm there isn't any fixed way but there is plenty for me to run with.