The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

Name

qbit::Exceptions - qbit exceptions

Synopsis

Usage:

use base qw(Exception);
package Sample;
use qbit;
sub ttt {
throw 'Fatal error';
# or
# throw Exception::Sample;
# or
# throw Exception::Sample 'Some text describing problem';
};
1;

One more sample. Here we are not catching proper exception, and the program stops. Finally blocks are always executed.

use base qw(Exception);
use base qw(Exception);
package Sample;
use qbit;
sub ttt {
my ($self) = @_;
try {
print "try\n";
throw Exception::Sample 'Exception message';
}
catch Exception::OtherSample with {
print "catch\n";
}
finally {
print "finally\n";
};
print "end\n";
}
1;

And one more code example. Here we have exception hierarchy. We are throwing a complex exception but we can catch it with it's parents.

use base qw(Exception);
package Sample;
use qbit;
sub ttt {
my ($self) = @_;
try {
print "try\n";
throw Exception::Complex 'Exception message';
}
catch Exception::Basic with {
print "catch\n";
}
finally {
print "finally\n";
};
print "end\n";
}
1;

In catch and finally blocks you can access $@ that stores exception object.