NAME
OpenInteract2::Exception - Base class for exceptions in OpenInteract
SYNOPSIS
# Standard usage
unless ( $user->check_password( $entered_password ) ) {
OpenInteract2::Exception->throw( 'Bad login' );
}
# Pass a list of strings to form the message
unless ( $user->check_password( $entered_password ) ) {
OpenInteract2::Exception->throw( 'Bad login', $object->login_attempted )
}
# Using an exported shortcut
use OpenInteract2::Exception qw( oi_error );
oi_error "Bad login", $object->login_attempted;
use OpenInteract2::Exception qw( oi_security_error );
oi_security_error "Action failed due to security requirements",
{ security_required => SEC_LEVEL_WRITE,
security_found => SEC_LEVEL_READ };
DESCRIPTION
First, you should probably look at Exception::Class for more usage examples, why we use exceptions, what they are intended for, etc.
This is the base class for all OpenInteract exceptions. It declares a handful of exceptions and provides shortcuts to make raising an exception easier and more readable.
METHODS
throw( @msg, [ \%params ])
This overrides throw() from Exception::Class to add a little syntactic sugar. Instead of:
$exception_class->throw( message => 'This is my very long error message that I would like to pass',
param1 => 'Param1 value',
param2 => 'Param2 value' );
You can use:
$exception_class->throw( 'This is my very long error message ',
'that I would like to pass',
{ param1 => 'Param1 value',
param2 => 'Param2 value' } );
And everything will work the same. Combined with the SHORTCUTS this makes for very readable code.
DECLARED EXCEPTION CLASSES
OpenInteract2::Exception::Application
Used for generic application errors.
Extra fields:
oi_package ($) (Optional)
Package from which the error was thrown.
OpenInteract2::Exception::Datasource
Used for errors related to datasources.
Extra fields:
datasource_name ($) (Optional)
Name of the datasource causing the error.
datasource_type ($) (Optional)
Type of datasource causing the error -- 'DBI', 'LDAP', etc.
connect_params (\%) (Optional)
Parameters used to connect. NOTE: There may be sensitive information (such as passwords) here.
OpenInteract2::Exception::Parameter
Used for parameter validation errors, including if a parameter is not found.
Extra fields:
parameter_fail ($) (Optional)
Name of the parameter that failed.
SHORTCUTS
You can import shortcuts for these methods
SEE ALSO
OpenInteract2::Exception::Security
COPYRIGHT
Copyright (c) 2002-2003 Chris Winters. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHORS
Chris Winters <chris@cwinters.com>