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

NAME

Python::Err - Python exception objects

SYNOPSIS

   # catching
   eval {
     ....
   }
   if ($@ && UNIVERSAL::iso("Python::Err")) {
       # deal with the exception
   }

   # raising
   if (... arg is not as expected ...) {
      Python:Err->Raise(Python::Err::TypeError, "a foo object expected");
   }

DESCRIPTION

Python exceptions are wrapped up in Python::Err objects. If perl calls some python function and this function raise an exception then $@ will end up as a reference to a Python::Err object.

The following methods are available:

$err->type

What kind of exception this is. It should usually be a reference to one of exception type objects described below.

$err->value

An assosiated value, usually just a human readable string explaining the reason for the failure.

$err->traceback

The traceback object contain stack trace information from the location where the exceptions where raised and down.

$err->as_string

Overloaded stringify. Allow python exceptions to be matched using regular expressions on $@ and to be printed. Exceptions are stringified as:

   "$type: $value"
$err->as_bool

Overloaded for boolean tests and will always return TRUE, so it is not actually very useful :-)

If perl code is known to be invoked from python code, then it might want to raise native python exceptions.

Python::raise($type, $value)

The raise() function will raise a python exception of the given type and pass with it the given value.

Standard exception type objects

References to all the standard python exception type objects can be obtained using the following names.

Python::Err::Exception

The root class for all exceptions.

Python::Err::StandardError

The base class for all built-in exceptions.

Python::Err::ArithmeticError

The base class for all arithmentic exceptions.

Python::Err::LookupError

The base class for indexing and key exceptions.

Python::Err::AssertionError

Failed assert statement.

Python::Err::AttributeError

Failed attribute reference or asssignment

Python::Err::EOFError

End of file.

Python::Err::FloatingPointError
Python::Err::EnvironmentError

Base class for errors that occur outside Python.

Python::Err::IOError

Failed I/O operation.

Python::Err::OSError
Python::Err::ImportError
Python::Err::IndexError
Python::Err::KeyError
Python::Err::KeyboardInterrupt
Python::Err::MemoryError
Python::Err::NameError
Python::Err::OverflowError
Python::Err::RuntimeError
Python::Err::NotImplementedError
Python::Err::SyntaxError
Python::Err::SystemError
Python::Err::SystemExit
Python::Err::TypeError
Python::Err::UnboundLocalError
Python::Err::UnicodeError
Python::Err::ValueError
Python::Err::ZeroDivisionError

If these functions are called with a single argument then they test if the object passed in is of the given type. The argument can be either a Python exception object or a Python::Err object. The test test does not yet consider inheritance of exceptions.

COPYRIGHT

(C) 2000-2001 ActiveState

This code is distributed under the same terms as Perl; you can redistribute it and/or modify it under the terms of either the GNU General Public License or the Artistic License.

THIS SOFTWARE IS PROVIDED BY ACTIVESTATE `AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ACTIVESTATE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

SEE ALSO

Python::Object, Python, perlmodule