Hello all,
I'm trying to learn exception handling using Error.pm (as recommended by
perl.com). Trouble is, I can't seem to get it right. Below (and
attached) is my source code in full:
use strict;
use warnings;
use Error;
$|=1;
try
{
print "before throw\n";
if (1)
{
print "throw error!";
callError();
}
print "no error\n";
}
catch MyException with
{
my $exception = shift;
print "error caught!\n";
print "caught: $exception\n";
}
finally
{
print "always executed";
};
sub callError
{
throw MyException ('Argh!');
}
package MyException;
use Error;
use base qw(Error);
use overload ('""' => 'stringify');
sub new
{
my $self = shift;
my $text = "" . shift;
my @args = ();
local $Error::Depth = $Error::Depth + 1;
local $Error::Debug = 1; # Enables storing of stacktrace
$self->SUPER::new(-text => $text, @args);
}
1;
My issues:
1. finally() is never called
2. catch() block is called even when there is no exception thrown (try
setting if(0) in the try block)
3. print "error caught!" is never called even when there is an exception
Any advice is appreciated. Thanks.
use strict;
use warnings;
my $array1 = ['a','b','c'];
my $array2 = ['d','e','f'];
@$array1 = (@$array1,@$array2);
print ''.scalar(@$array1);
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs