matlab.exception.PyException 类
包: matlab.exception
捕获 Python 异常的错误信息
描述
处理 matlab.exception.PyException
对象中的信息,以解决从 MATLAB® 调用的 Python® 方法引发的 Python 错误。此类派生自 MException
。
创建对象
您不要显式构造 matlab.exception.PyException
对象。每当 Python 抛出异常时,MATLAB 会自动构造一个 PyException
对象。PyException
对象将包装原始的 Python 异常。
属性
ExceptionObject
— 对象
异常对象
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 异常
生成一个 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 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)