The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Text::BSV::Exception - create an object that can be thrown using the Perl "die" function (which can accept a reference instead of a string) and caught using "eval", which stores the object in $EVAL_ERROR ($@).

SYNOPSIS

  use Text::BSV::Exception;
  my $exception = Text::BSV::Exception->new($Text::BSV::Exception::GENERAL,
    "Couldn't do stuff because of the thing.");
  my $fancy_exception = Text::BSV::Exception->new(
    $Text::BSV::Exception::NULL_POINTER,
    "Couldn't do stuff because the thing was pointing to nothing.",
    {"IsFatal" => $TRUE, "Time" => "17:47:18"});
  my $exception_type = $exception->get_type();
  my $message_string = $exception->get_message();
  my $hash_ref = $fancy_exception->get_data();

DESCRIPTION

This module defines a package for creating a Text::BSV::Exception object, which can be thrown using the Perl "die" function and caught using "eval".

In addition to the class-name argument, which is passed in automatically when you use the Text::BSV::Exception->new() syntax, the constructor takes an exception type, a message string, and an optional hash reference that points to arbitrary structured data pertaining to the exception.

The exception type must be one of the following constants defined in the Text::BSV::Exception package:

    $DIRECTORY_NOT_FOUND
    $FILE_NOT_FOUND
    $GENERAL
    $ILLEGAL_ARGUMENT
    $INVALID_CHARACTER
    $INVALID_DATA_FORMAT
    $INVALID_REGEX
    $IO_ERROR
    $NULL_POINTER
    $UNSUPPORTED_OPERATION

The constructor returns a reference to a Text::BSV::Exception object, which is implemented internally as a hash. All functionality is exposed through methods.

PREREQUISITES

This module requires Perl 5, version 5.10.1 or later.

METHODS

Text::BSV::Exception->new($exception_type, $message, $optional_hash_ref);

This is the constructor.

$exception->get_type();

This is the accessor method for retrieving the exception type, which must be one of the following constants defined in the Text::BSV::Exception package:

    $DIRECTORY_NOT_FOUND
    $FILE_NOT_FOUND
    $GENERAL
    $ILLEGAL_ARGUMENT
    $INVALID_CHARACTER
    $INVALID_DATA_FORMAT
    $INVALID_REGEX
    $IO_ERROR
    $NULL_POINTER
    $UNSUPPORTED_OPERATION
$exception->get_message();

This is the accessor method for retrieving the message.

$exception->get_data();

This is the accessor method for retrieving any structured data provided with the exception. If there is no structured data, the get_data() method returns a reference to an empty hash.

AUTHOR

Benjamin Fitch, <blernflerkl@yahoo.com>

COPYRIGHT AND LICENSE

Copyright 2010 by Benjamin Fitch.

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