Name

qbit::Exceptions - qbit exceptions

Synopsis

Usage:

package Exception::Sample;
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.

package Exception::Sample;
use base qw(Exception);

package Exception::OtherSample;
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.

package Exception::Basic;
use base qw(Exception);

package Exception::Complex;
use base qw(Exception::Basic);

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.