Fri, 17 May 2024


How to catch exceptions with eval in Perl?

By: Peter, NetArt Media
Fri, 11 December 2020

This approach is useful when you wish to see the reason why the script "has died" in some part of the program.

Consider the following example:

eval
{

die("REASON"); # the script dies for some reason

};

if ($@) # $@ contains the exception that was thrown
{
print $@;
}


Category: Web Development
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox