NAME
SPOPS::Manual::Error - SPOPS Error handling
DESCRIPTION
Error handling in SPOPS is fairly straightforward. Most (if not all) methods that can encounter some sort of error let the caller know about the error by throwing a die
. The error thrown is a simple error message -- additional information can be inspected through variables in SPOPS::Error.
The variables used are:
user_msg ($)
A generic message that is suitable for showing a user. When telling a user something went wrong, you do not want to tell them:
execute called with 2 bind variables when 1 are needed
instead, you want to tell them:
Database query failed to execute
Typically, this is the message that the SPOPS class will die()
with.
system_msg ($)
Even though you do not want to show your users details of the error, you still need to know them! The variable system_msg gives you details regarding the error.
type ($)
SPOPS knows about a few types of errors. Some depend on your SPOPS implementation (e.g., DBI, dbm, LDAP, etc.). Others can be:
security: There is a security violation and the action could not be completed
package ($)
Set to the package from where the error was thrown.
method ($)
Set to the method from where the error was thrown. (If set automatically, this is a fully-qualified subroutine name.)
filename ($)
Set to the filename from where the error was thrown.
line ($)
Set to the line number from where the error was thrown.
extra (\%)
Different SPOPS classes have different information related to the current request. For instance, DBI errors will typically fill the 'sql' and 'values' keys. Other SPOPS implementations may use different keys; see their documentation for details.
EXAMPLES
1: my $news_id = $q->param( 'news_id' );
2: my $news = eval { My::News->fetch( $news_id ) }
3: if ( $@ ) {
4: my $error_info = SPOPS::Error->get;
5: log_error( $error_info );
6: if ( $error_info->{type} eq 'security' ) {
7: print "Cannot retrieve News article -- security violation.";
8: }
9: else {
10: print "Cannot retrieve News article! Please contact administrator.";
11: }
12: }
13:
14: print "$news->{title}\n$news->{posted_on}\n$news->{content}\n";
COPYRIGHT
Copyright (c) 2001 Chris Winters. All rights reserved.
See SPOPS::Manual for license.
AUTHORS
Chris Winters <chris@cwinters.com>