From: Jesse Luehrs Date: Fri, 6 May 2011 23:25:29 +0000 (-0500) Subject: use Try::Tiny in this example X-Git-Tag: 2.0003~40 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5954778473f57c481ed0308bf5c74701bb05a37f;p=gitmo%2FMoose.git use Try::Tiny in this example --- diff --git a/lib/Moose/Cookbook/Snack/Types.pod b/lib/Moose/Cookbook/Snack/Types.pod index 5da470e..2b6670b 100644 --- a/lib/Moose/Cookbook/Snack/Types.pod +++ b/lib/Moose/Cookbook/Snack/Types.pod @@ -16,12 +16,14 @@ __END__ has 'y' => ( isa => 'Int', is => 'rw' ); package main; + use Try::Tiny; - my $point = eval { Point->new( x => 'fifty', y => 'forty' ); }; - - if ($@) { - print "Oops: $@"; + my $point = try { + Point->new( x => 'fifty', y => 'forty' ); } + catch { + print "Oops: $_"; + }; my $point; my $xval = 'forty-two'; @@ -45,7 +47,7 @@ Moose will die with an explicit error message. The error will include the attribute name, as well as the type constraint name and the value which failed the constraint check. -We use C to catch this error message in C<$@>. +We use L to catch this error message. Later, we get the L object from a L and use the L