Main Content

Python 例外の処理

MATLAB® は、Python® によってスローされた例外をキャッチし、MException クラスから派生した matlab.exception.PyException オブジェクトに変換します。以下に例を示します。

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)

MATLAB に次の形式のエラー メッセージが表示された場合、詳細は Python のドキュメンテーションを参照してください。

Python Error: Python class: message

参考