The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Exception::Like - Exception-like Error Checking

SYNOPSIS

  #Package file:
  package Exception::LikeTest;

  use Exception::Like MyException=>'This is my exception';

  use strict;
  use warnings;

  sub new {
    my $this = shift;
    my $class = ref($this) || $this;
    my $self = bless {}, $class;

    return $self;
  }

  sub fails {
    err(MyException,'just felt like erroring');
    return;
  }

  #Program file:
  use Exception::LikeTest;
  $a = new Exception::LikeTest;
  $r = $a->fails();

  unless ($r) {
    # Error ocured!
    if ($a->errno() eq MyException) {
      warn MyException, " occured.\n";
    }
    else {
      die $a->errstr();
    }
  }

  #To list all the defined Exceptions (or Error IDs)
  use Exception::Like;
  print "$_\n" for Exception::Like->list_defined_exceptions();

DESCRIPTION

Instead of using try-cacth method, this module relies on good old return-value-check method. But gives its users the chance to identify error types as in handling exceptions, and stacking errors.

METHODS

err(ErrorID,'Extra Description')

Used by the error reporting program or module, to push an error into the error stack. Always returns undef.

errno() errnos()

Returns last occured ErrorID. errnos returns an array of error IDs from the error stack.

errstr() errstrs()

Returns last occured Error String. errstrs returns an array of error strings from the error stack.

dump_err()

Returns Error Stack data structure.

clear_err()

Clear the error stack.

errstack()

Returns last occured Error's Caller Stack with line breaks for easy reporting.

list_defined_exceptions()

Returns a list of all defined exceptions. Not exported.

EXPORT

err, errno, errnos, errstr, errstrs, dump_err, clear_err, errstack are exported one level. All Error IDs Exported to all levels.

EXPORT WARNING

All Error IDs Exported to all levels by default.

AUTHOR

Ziya Suzen <ziya@ripe.net>

SEE ALSO

perl(1), Error, Exception::Class, Exception.

COPYRIGHT

Copyright (c) 2002 RIPE NCC

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 228:

'=item' outside of any '=over'

Around line 259:

You forgot a '=back' before '=head2'