More Ouch

The response to my original Ouch post has been overwhelming. Based upon the number of responses it got and the number of emails I personally received about it, Ouch must have struck a cord.

I've taken the feedback I've received and released Ouch 0.03. New feature details after the jump.

The new features are:

Non-integer codes - You can now use a code like ouch 'missing_param', 'Email address needed.', 'email'; And check for it with kiss 'missing_param'.

hug - Catch any exception, including non-ouch exceptions.

use Ouch qw(:traditional) - Imports four new functions into the namespace. They are:

try - A nice wrapper around eval.
throw - An alias for ouch.
catch - An alias for kiss.
catch_all - An alias for hug.

The usage of these new funcs work like this:

 use Ouch qw(:traditional);

my $e = try {
throw 404, 'File not found.';

if ( catch 404, $e ) {
# do the big thing
elsif ( catch_all $e ) {
# make it stop
else {
# make it go

Thanks for all the feedback. Enjoy!


Your version of try seems inadequate when compared to that of Try::Tiny.

I think he's saying that instead of rolling your own, you should look into tieing Try::Tiny's try() into ouch. :)

Oh, another suggestion:

Maybe a hug_with() function would be neat. Instead of constructing huge honking if/elsif/else blocks i'd prefer to do this:

404 => sub { do_missing_page( $current ) },
'Email address needed.' => \&email_missing,
or die_unknown();

@ JT Smith :

Try::Tiny pod explains why it's important to localize $@. The DESTROY example is especially important, as it's more common than on might think.

Ouch's implementaion of try() is not good enough for me to use Ouch instead of Try::Tiny. I see why you wanted to improve on Ouch 0.3 based on comments, but for me the real benefit of Ouch is the simplicity. I loved the idea of Ouch, because it didn't follow the traditional try/catch direction. But now it looks like yet another trycatch attempt.

Leave a comment

About JT Smith

user-pic My little part in the greater Perl world.