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.

Construction

e = matlab.exception.PyException(msgID,errMsg,excObj) constructs instance e of matlab.exception.PyException class.

Input Arguments

expand all

Message identifier, specified as a character vector.

Error message, specified as a character vector.

Exception object, specified as the pythonclass that caused the exception.

Output Arguments

expand all

Instance of matlab.exception.PyException class

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.

Tips

  • Typically, 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.

Examples

expand all

Generate a Python exception and display 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)

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

Introduced in R2014b

Was this topic helpful?