Main Content

matlab.exception.PyException 类

命名空间: matlab.exception

捕获 Python 异常的错误信息

描述

处理 matlab.exception.PyException 对象中的信息,以解决从 MATLAB® 调用的 Python® 方法引发的 Python 错误。此类派生自 MException

创建对象

您不要显式构造 matlab.exception.PyException 对象。每当 Python 抛出异常时,MATLAB 会自动构造一个 PyException 对象。PyException 对象将包装原始的 Python 异常。

属性

全部展开

Python sys.exc_info 函数的结果。要了解函数返回的内容信息,请键入:

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.

示例

全部折叠

生成一个 Python 异常并显示信息。当 MATLAB 显示包含文本 Python Error 的消息时,请参阅您的 Python 文档以了解详细信息。

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)

版本历史记录

在 R2014b 中推出