Reference

Zoidberg::Utils::Error(3pm)

Zoidberg::Utils::Error - OO error handling

        use Zoidberg::Utils qw/:error/;

        sub some_command {
                error "Wrong number of arguments"
                        unless scalar(@_) == 3;
                # do stuff
        }

        # this raises an object oriented exception

This library supplies the methods to replace "die()". These methods raise an exception but passing a object containing both the error string and caller information. Thus, when the exception is caught, more subtle error messages can be produced depending on for example verbosity settings. If the global variable $ERROR_CALLER is set in a package using this library, all errors will pretend to originate from the call-frame identified by the number of the variable. Setting $ERROR_CALLER to 1 will result in Carp like behaviour. Although when working within the Zoidberg framework this module should be used through the Zoidberg::Utils interface, it also can be used on it's own. By default "error()", "bug()" and "todo()". When using the Zoidberg::Utils interface you also get "complain()", which actually belongs to Zoidberg::Utils::Output.
Exported methods Raises an exception which passes on "\%error". Like "error()", but with "is_bug" field set. Like "error()", but with "is_todo" field set.
Object methods Returns an error string.

Known options: Types 'gnu' and 'perl' are supported. The format 'perl' is the default, 'gnu' is used by zoidberg's "complain()" function. Is automaticly called by "die()" when you use for example:

        use Zoidberg::Utils::Error;

        eval { error 'test' }
        die if $@; # die is called without explicit argument !

See also "die" in perlfunc. The exception raised can have the folowing attributes: Original error string. The global $Zoidberg::Utils::Error::Scope at the time of the exception. This is used to hide the real caller information in the gnu formatted error string with for example the name of a builtin command. Calling package. Source file where the exception was raised. Line in source file where the exception was raised. The calling package had the global variable $DEBUG set to a non-zero value. When debug was in effect, the caller stack is traced for a number of frames equal to the value of the debug variable and put in the stack attribute. This exception should never happen, if it does this is considered a bug. This exception is raised because some feature isn't yet implemented. Array of arrays containg information about file and line numbers where this error was propagated, see "PROPAGATE".
Overloading When the methods are given a hash reference as one of there arguments this hash overloads the default values of %error. Thus it is possible to fake for example the calling package, or add meta data to an exception. Jaap Karssenberg ⎪⎪ Pardus [Larus] <[email protected]> Copyright (c) 2003 Jaap G Karssenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Zoidberg, Zoidberg::Utils, <http://www.gnu.org/prep/standards_15.html#SEC15>

History