#!/usr/bin/env perl
#
# test.pl - description
#
# Copyright (C) 2009 Stefan Pfetzing
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
use warnings;
use strict;
use Error::TryCatch;
use Error::Simple;
sub good() {
return;
}
sub fail() {
throw new Error::Generic
-text => "well, no one can live in danger forever";
}
sub fail_simple() {
throw new Error::Simple("Error::Simple failed.");
}
sub bad() {
die "argh";
}
sub peng {
try {
print "peng(): try {} block\n";
good(); # macht nix
fail_simple(); # wirft nen Error::Simple
fail(); # wirft nen Error::Generic
bad(); # macht die()
print "peng(): try {} block done...\n";
} catch Error::Unhandled {
print "peng(): unhandled die: $@\n";
} otherwise {
my $e = shift;
throw $e;
};
}
try {
peng(); # hier soll nen MyError geflogen kommen
} catch Error::Simple {
print "peng(): simple error\n";
} catch Error::Generic {
print "peng(): generic error\n";
} otherwise {
print "irgend nen die: $@\n";
};
print "hm\n";
# vim:set ft=perl fdm=marker fmr=><!>,<!><: