GX::Exception - Exception class
# Load the module use GX::Exception; # Try eval { throw "Oops!"; }; # Catch if ( $@ ) { warn "Exception: $@"; } # Same as above, but with proper localization of $@ try { throw "Oops!"; } catch { warn "Exception: $_"; };
This module provides the GX::Exception class.
new
Returns a new GX::Exception object.
$exception = GX::Exception->new( %attributes );
message ( string )
message
An error message.
stack_trace ( GX::Exception::StackTrace object )
stack_trace
A stack trace object.
subexception ( GX::Exception object | string )
subexception
A subexception.
verbosity ( integer )
verbosity
The default verbosity level. Possible values are: "0" (only prints the error message), "1" (prints the error message and also the error messages of all subexceptions), "2" (prints a short stack trace) or "3" (prints a full stack trace). The default value is "0".
$exception ( GX::Exception object )
$exception
Alternative syntax:
$exception = GX::Exception->new( $message ); $exception = GX::Exception->new( $subexception );
$message ( string )
$message
$subexception ( GX::Exception object )
$subexception
as_string
Returns a text representation of the exception.
$string = $exception->as_string( $verbosity );
$verbosity ( integer ) [ optional ]
$verbosity
Possible values: "0", "1", "2" or "3". Defaults to the value returned by verbosity().
verbosity()
$string ( string )
$string
In list context, as_string() returns individual lines of text.
as_string()
@strings = $exception->as_string( ... );
@strings ( strings )
@strings
complain
Raises the exception just like throw(), but with the stack trace originating at the caller.
throw()
$exception->complain;
This method can also be called as a class method. See throw() for details.
Returns / sets the error message.
$message = $exception->message; $message = $exception->message( $message );
$message ( string ) [ optional ]
Returns / sets the associated stack trace object.
$stack_trace = $exception->stack_trace; $stack_trace = $exception->stack_trace( $stack_trace );
$stack_trace ( GX::Exception::StackTrace object | undef ) [ optional ]
$stack_trace
undef
$stack_trace ( GX::Exception::StackTrace object | undef )
In list context, stack_trace() returns a list with the individual stack frame objects.
stack_trace()
@frames = $exception->stack_trace( ... );
@frames ( GX::Exception::StackTrace::Frame objects )
@frames
Returns / sets the associated subexception.
$subexception = $exception->subexception; $subexception = $exception->subexception( $subexception );
$subexception ( GX::Exception object | string | undef ) [ optional ]
$subexception ( GX::Exception object | undef )
throw
Throws the exception by calling die().
die()
$exception->throw;
This method can also be called as a class method:
GX::Exception->throw; GX::Exception->throw( $message ); GX::Exception->throw( $subexception ); GX::Exception->throw( %attributes );
This will create a new instance of the exception class (see new() for details) on which throw() is then called.
new()
Returns / sets the default verbosity level.
$verbosity = $exception->verbosity; $verbosity = $exception->verbosity( $verbosity );
Possible values: "0", "1", "2" or "3".
$verbosity ( integer )
The following functions are exported by default.
catch
This function is meant to be used with try(). It simply returns the first argument passed to it, which must be a block of code.
try()
try { # Block of code ... } catch { # Block of code ... };
Throws an exception with the the stack trace originating at the caller.
complain $message; complain $subexception;
Throws an exception.
throw $message; throw $subexception;
try
This function expects a "try" block as its first argument and optionally a "catch" block as its second argument (see catch() above).
catch()
try { # Block of code ... };
GX::Exception::StackTrace
GX::Exception::StackTrace::Frame
GX::Exception::Formatter::HTML
Jörg A. Uzarek <uzarek@runlevelnull.de>
Copyright (c) 2009-2011 Jörg A. Uzarek.
This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.
To install GX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GX
CPAN shell
perl -MCPAN -e shell install GX
For more information on module installation, please visit the detailed CPAN module installation guide.