Main Content

matlab.exception.PyException class

Package: matlab.exception

Capture error information for Python exception

Description

Process information from a matlab.exception.PyException object to handle Python® errors thrown from Python methods called from MATLAB®. This class is derived from MException.

Creation

You do not construct a matlab.exception.PyException object explicitly. MATLAB automatically constructs a PyException object whenever Python throws an exception. The PyException object wraps the original Python exception.

Properties

expand all

Result from Python sys.exc_info function. For information about what the function returns, type:

help('py.sys.exc_info')
exc_info() -> (type, value, traceback)

Return information about the most recent exception caught by an except
clause in the current stack frame or in an older stack frame.

Examples

collapse all

Generate a Python exception and display information. When MATLAB displays a message containing the text Python Error, refer to your Python documentation for more information.

try
  py.list('x','y',1)
catch e
  e.message
  if(isa(e,'matlab.exception.PyException'))
    e.ExceptionObject
  end
end
ans =

Python Error: TypeError: list() takes at most 1 argument (3 given)

ans = 

  Python tuple with no properties.

    (<type 'exceptions.TypeError'>, TypeError('list() takes at most 1 argument (3 given)',), None)

Version History

Introduced in R2014b