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::System - The exception class for system or library calls

SYNOPSIS

  # Loaded automatically if used as Exception::Base's argument
  use Exception::Base ':all',
    'Exception::System',
    'Exception::File' => { isa => 'Exception::System' };

  try eval {
    my $file = "/notfound";
    open FILE, $file
        or throw 'Exception::File' =>
                 message=>"Can not open file: $file",
                 file=>$file;
  };
  if (catch 'Exception::System' => my $e) {
    if ($e->isa('Exception::File')) { warn "File error:".$e->{errstr}; }
    if ($e->with(errname=>'ENOENT')) { warn "Caught not found error"; }
  }

DESCRIPTION

This class extends standard Exception::Base with handling system or library errors. The additional fields of the exception object are filled on throw and contain the error message and error codes.

PREREQUISITIES

CONSTANTS

FIELDS

Declaration of class fields as reference to hash.

FIELDS

Class fields are implemented as values of blessed hash. The fields of base class are inherited. See Exception::Base to see theirs description.

errstr (ro)

Contains the system error string fetched at exception throw. It is the part of the string representing the exception object. It is the same as $! variable in string context.

  eval { throw 'Exception::System' => message=>"Message"; };
  catch 'Exception::System' => my $e
    and print $e->{errstr};
errstros (ro)

Contains the extended system error string fetched at exception throw. It is the same as $^E variable.

  eval { throw 'Exception::System' => message=>"Message"; };
  if (catch 'Exception::System' => my $e) {
    if ($e->{errstros} ne $e->{errstr}) {
      print $e->{errstros};
    }
  }
errno (ro)

Contains the system error number fetched at exception throw. It is the same as $! variable in numeric context.

  eval { throw 'Exception::System' => message=>"Message"; };
errname (ro)

Contains the system error constant from the system error.h include file.

  eval { throw 'Exception::System' => message=>"Message"; };
  catch 'Exception::System' => my $e and $e->{errname} eq 'ENOENT'
    and $e->throw;

METHODS

stringify([$verbosity[, $message]])

Returns the string representation of exception object. The format of output is "message: error string".

  eval { open F, "/notexisting"; throw 'Exception::System'; };
  print $@->stringify(1);
  print "$@";

PRIVATE METHODS

_collect_system_data

Collect system data and fill the attributes of exception object. This method is called automatically if exception if throwed.

See Exception::Base.

SEE ALSO

Exception::Base.

BUGS

The module was tested with Devel::Cover and Devel::Dprof.

If you find the bug, please report it.

AUTHOR

Piotr Roszatycki <dexter@debian.org>

LICENSE

Copyright (C) 2007, 2008 by Piotr Roszatycki <dexter@debian.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html