# in MyApp::Util sub convert_datetime { my ( $self, $incoming_datetime ) = @_; my $new_dt; eval { $new_dt = DateTime::Format::ISO8601->parse_datetime( $incoming_datetime ); }; return undef if $@; # No error, now we can convert the date (not shown) } #### my $bogus_datetime = MyApp::Util->convert_datetime("FOO"); is ($bogus_datetime, undef, "convert_datetime doesn't blow up if sent bogus date"); #### ok 141 - convert_datetime doesn't blow up if sent bogus date Invalid date format: at /path/to/MyApp/Util.pm line 818. eval {...} called at /path/to/MyApp/Util.pm line 818 MyApp::Util::convert_datetime("MyApp::Util", "FOO") called at t/Util.t line 297 ...propagated at t/Util.t line 298. #### #!/usr/bin/env perl use strict; use warnings; use DateTime::Format::ISO8601; eval {my $foo = DateTime::Format::ISO8601->parse_datetime("FOO");}; print "ERROR\n" if $@;