Perl does not provide try or catch keywords. To catch the โexceptionsโ thrown by die , you can set the $SIG{__DIE__} or use eval . The shape of the block is preferable to the shape of the string, since parsing occurs once at compile time.
eval { // statement 1 // statement 2 } if ( $@ ) { warn "caught error: $@ "; }
There are various modules that provide more traditional try like functionality, such as Try::Tiny .
source share