eval { do_whatever() }; if ($@) { # handle error ... }