use Foo; my $thing = Foo->new; my $success = $thing->set_foo( -2 ); if ( $success ) { # do something } else { # you can also do if ( $thing->error ) { die $thing->errmsg; }