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

Name

Object::Relation::Exceptions - Object::Relation exception object definitions

Synopsis

  use Object::Relation::Exceptions ':all';
  throw_fatal 'Whoops!';

  # The error is fully localizable.
  throw_fatal ['Unknown value "[_1]"', 'foo'];

Description

This class defines Object::Relation exception objects. It subclasses Exception::Class, which provides a robust exception implementation. It extends Exception::Class by requiring localizable error messages. All error messages must be represented in the appropriate Object::Relation::Language lexicons.

There currently four major classes of exceptions:

Object::Relation::Exception::Fatal

This class and its subclasses represent fatal, non-recoverable errors. Exceptions of this sort are unexpected, and should be reported to an administrator or to the Object::Relation developers.

Object::Relation::Exception::Error

This class and its subclasses represent non-fatal errors triggered by invalid data. These can be used to let users know that the data they've entered is invalid.

Object::Relation::Exception::ExternalLib

This class will never has its error message localized. This is so that it can be thrown by libraries not under direct Object::Relation control and therefore are not localizable. This class is also used for the global $SIG{__DIE__} handler, so that exceptions always include a nicely formatted stack trace.

Object::Relation::Exception::DBI

This class is used solely for handling exceptions thrown by DBI. You should never need to access it directly.

Exception Classes

The exception classes generated by this module are as follows:

Object::Relation::Exception

Object::Relation exception base class. It generally should not be thrown, only its subclasses.

Object::Relation::Exception::Fatal

Base class for fatal exceptions. Alias: throw_fatal.

Object::Relation::Exception::Fatal::Invalid

Invalid data exception. Thrown when an invalid value is assigned to a Object::Relation class attribute. Alias: throw_invalid.

Object::Relation::Exception::Fatal::ReadOnly

ReadOnly exception. Thrown when an someone attempts to assign a value to a read-only attribute. Alias: throw_read_only.

Object::Relation::Exception::Fatal::Language

Localization exception. Thrown if an error is encountered while attempting to localize a string. Alias: throw_lang.

Object::Relation::Exception::Fatal::Stat

File status exception. Thrown if an error is encountered while attempting to stat a file. Alias: throw_stat.

Object::Relation::Exception::Fatal::IO

IO exception. Thrown if an error is encountered while attempting to read or write to a file. Alias: throw_io.

Object::Relation::Exception::Fatal::Unimplemented

Unimplemented exception. Thrown if a feature has not yet been implemented or must be overridden in a subclass. Alias: throw_unimplemented.

Object::Relation::Exception::Fatal::RequiredArguments

Missing arguments exception. Thrown if required arguments to a method are not present. Alias: throw_required.

Object::Relation::Exception::Fatal::NotFound

Object Not Found exception. Thrown if something searched for is not found. Usually this is for objects in data stores, but also might be used for anything that is being looked for (such as a file). Alias: throw_not_found.

Alias: throw_not_found.

Object::Relation::Exception::Fatal::Unsupported

Unsupported feature exception. Thrown if code attempts to use an unsupported feature. Alias: throw_unsupported.

Object::Relation::Exception::Fatal::XML

XML parse exception. Thrown if a problem is found parsing XML. Alias: throw_xml.

Object::Relation::Exception::Fatal::InvalidClass

Invalid class exception. Thrown if an incorrect class is encountered. Alias: throw_invalid_class.

Object::Relation::Exception::Fatal::InvalidAttribute

Invalid attribute exception. Thrown if an incorrect attribute is encountered. Alias: throw_invalid_attr.

Object::Relation::Exception::Fatal::UnknownClass

Unknown class exception. Thrown if an unknown class is encountered. Alias: throw_unknown_class.

Object::Relation::Exception::Fatal::Attribute

Object::Relation attribute exception. Thrown if a Object::Relation attribute is used incorrectly, such as "unknown attributes" or trying to use a non-unique attribute where a unique attribute would be used. Alias: throw_attribute.

Object::Relation::Exception::Fatal::Search

Store search exception. Thrown if data store cannot figure out how to respond to a search request. Alias: throw_search.

Object::Relation::Exception::Fatal::Setup

Setup exception. Thrown if there is an error when setting up a data store. Alias: throw_setup.

Object::Relation::Exception::Fatal::Panic

Panic exception. This internal exception should (theoretically) never be thrown. It only occurs if the internal state of something has reached a point that cannot occur. For example, an "ANY" search in a store class can only occur if the values searched on are contained in an array reference. If an ANY search occurs and the values are not an array reference, a panic is thrown. Alias: panic.

Object::Relation::Exception::Error

Base class for error exceptions. These are non-fatal errors, generally triggered by problems with data entered by users. Alias: throw_error.

Object::Relation::Exception::Error::Auth

Authentication failure. Thrown when authentication fails. Alias: throw_auth.

Object::Relation::Exception::ExternalLib

Class for exceptions thrown external to Object::Relation code. Exceptions of this class behave just like any other Object::Relation exception objects, except that error messages are not localized. Alias: throw_exlib.

Interface

Functions

In addition to the functions that can be imported to throw the above exceptions, there are a few other functions that may be imported into a client class.

isa_obj_rel_exception

  if (isa_obj_rel_exception($@))
      print 'A Object::Relation exception was thrown';
      print "...and it was fatal!' if isa_obj_rel_exception($@, 'Fatal');
  }

This function returns true if the argument passed to it is a Object::Relation exception. The optional second argument can be used to test for a specific Object::Relation exception. If no such exception exists, an exception will be thrown.

isa_exception

  if (isa_exception($@)) {
      print "What we have here...is an exception object";
  }

This function returns true if the argument passed to it is an Exception::Class object.

sig_handlers

  sig_handlers(0);

This function accepts a boolean value. If true, it turns on stack traces via the DIE signal handler. If false, it disables them. If called without arguments, it merely returns a boolean value indicating whether or not the signal handlers are enabled.

Constructors

new

  my $err = Object::Relation::Exception->new("Whoops!");
  my $err = Object::Relation::Exception->new(error => 'Whoops!');
  my $err = Object::Relation::Exception->new(['Unknown value "[_1]"', 'foo']);
  my $err = Object::Relation::Exception->new(
      error => ['Unknown value "[_1]"', 'foo']
  );

Creates and returns a new exception object. Use this method with die to throw exceptions yourself, or if you don't want to import any throw_ functions into your namespace. Otherwise, a throw_ function is generally the preferred way to throw an exception. Besides, it requires less typing!

The base class supports only a single parameter, error, for the exception error message. If only a single argument is passed to new(), it is assumed to be the error parameter. Other exception classes may support other parameters; consult their <descriptions|"Exception Classes"> for details. All throw_ functions for the exception subclasses support the parameters that correspond to their respective classes.

Instance Methods

as_string

  my $string $err->as_string;

Returns a stringified representation of the exception, which includes the full error message and the stack trace. The method overrides stringification (double-quoted string context), so its return value is output whenever an exception object is printed.

We override the base class version of this method in order to provide a nicer, more legible stack trace, rather than the default Carp-style trace.

trace_as_text

  my $trace = $err->trace_as_text;

Returns a stringified representation of the stack trace for the exception object. Used by as_string() to pretty-print the stack trace.

Copyright and License

Copyright (c) 2004-2006 Kineticode, Inc. <info@obj_relode.com>

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