Difference between revisions of "Perl eval"

From Teknologisk videncenter
Jump to: navigation, search
m (New page: Perl eval can be used as a '''try''' and '''catch''' error recovery procedure <source lang="perl"> eval { # try }; if($@) { # catch } </source> Category:Perl)
 
m
Line 1: Line 1:
Perl eval can be used as a '''try''' and '''catch''' error recovery procedure
+
Perl eval can be used as '''try''' and '''catch''' exception handling.
 
<source lang="perl">
 
<source lang="perl">
 
eval
 
eval
Line 10: Line 10:
 
}
 
}
 
</source>
 
</source>
 +
= Throwing an exception =
 
[[Category:Perl]]
 
[[Category:Perl]]
 +
<source lang="perl">
 +
eval
 +
{
 +
    # try
 +
    die "Exception text to be catched";
 +
};
 +
if($@)
 +
{
 +
    # catch
 +
}
 +
</source>

Revision as of 10:54, 22 March 2009

Perl eval can be used as try and catch exception handling.

eval
{
    # try
};
if($@)
{
    # catch
}

Throwing an exception

eval
{
    # try
    die "Exception text to be catched";
};
if($@)
{
    # catch
}