Why not adopt me?
This distribution is up for adoption!
If you're interested then please contact the PAUSE module admins via
email.
Name
qbit::Exceptions - qbit exceptions
Synopsis
Usage:
package
Exception::Sample;
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.
package
Exception::Sample;
package
Exception::OtherSample;
package
Sample;
use
qbit;
sub
ttt {
my
(
$self
) =
@_
;
try
{
"try\n"
;
throw Exception::Sample
'Exception message'
;
}
catch
Exception::OtherSample
with
{
"catch\n"
;
}
finally
{
"finally\n"
;
};
"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.
package
Exception::Basic;
package
Exception::Complex;
package
Sample;
use
qbit;
sub
ttt {
my
(
$self
) =
@_
;
try
{
"try\n"
;
throw Exception::Complex
'Exception message'
;
}
catch
Exception::Basic
with
{
"catch\n"
;
}
finally
{
"finally\n"
;
};
"end\n"
;
}
1;
In catch and finally blocks you can access $@ that stores exception object.