Merror

1.3

Introduction

Merror is a class implementing a mechanism to handle errors OOP style which means that it gaves you the ability to easily set or get error codes, error descriptions and gives you the ability to print out a stacktrace.

Author

Markus Mazurczak <coding@markus-mazurczak.de>

Bugtracking

If you find any bugs or you want to have some features included register at http://mantis.markus-mazurczak.de

Installation

Installation must be done as with every other standard perl module installed manually: If yout want to install that module in some other than your perl standard paths specify PREFIX=.
e.g.:

Example

Lets consider we created the following errormapping file named "errorcodes" in /home/foobar/test: Lets create the following test perl module:
package test:
BEGIN {
  use strict;
  use warnings;
  use File::Spec;
  use File::Basename;
}

use Merror;

sub new {
  my $invocant = shift;
  my $class = ref($invocant) || $invocant;
  my $self = {
    MERROR => Merror->new(stackdepth => 16, errorfile => "/home/foobar/test/errorcodes", ramusage => 1);
      TEXT => "Test messages";
  };

  bless $self, $class;
  return($self);
}

sub tellme {
  my $self = shift;
my $errorcode = shift;
  #indicate that an error happened
  $self->{MERROR}->error(1);
  #set an error code and the mapped description
  $self->{MERROR}->mappedError($errorcode);
}

sub tellmethesecond {
  my $self = shift;
  #indicate that an error happened
  $self->{MERROR}->error(1);
  #set an error code 
  $self->{MERROR}->ec($errorcode);
#set the error description
$self->{MERROR}->et("This message will be the error description");
}

1;
Now lets create a file foo.pl in /home/foobar/test
#!/usr/bin/perl
BEGIN {
  use strict;
  use warnings;
  use Merror;
}

use test;

my $foobar = Test->new();

$foobar->tellmethesecond();
if($foobar->{MERROR}->error()) {
  #print out the error code
  print("Errorcode: " . $foobar->{MERROR}->ec . "\n");
  #print out the error description
  print("Errordescription: " . $foobar->{MERROR}->et . "\n");
  #print out a stacktrace
  print("Stacktrace: \n");
  $foobar->{MERROR}->stacktrace;
}

$foobar->tellme();
if($foobar->{MERROR}->error(1)) {
  #print out the error code
  print("Errorcode: " . $foobar->{MERROR}->ec . "\n");
  #print out the error description
  print("Errordescription: " . $foobar->{MERROR}->et . "\n");
  #print out a stacktrace
  print("Stacktrace: \n");
  $foobar->{MERROR}->stacktrace;
}

Errormapping file syntax

Every line of the errorfile consists out of 3 parts. It does not matter if there are any whitespaces between the parts, they will be substituted. The perl regexp looks like the following:
/^(\d{1,})\s{0,}:\s{0,}(.*)/

Generated on Mon Mar 8 17:18:20 2010 for Merror by  doxygen 1.5.8