Main Content

getReport

例外のエラー メッセージを取得する

説明

msgText = getReport(exception) は例外についてのエラー メッセージを受け取り、それを書式化されたテキスト msgText として返します。メッセージは、MException オブジェクト exceptionmessage プロパティの値です。これは、MATLAB® が例外をスローするときに表示するテキストと同じです。

msgText = getReport(exception,type) は、type によって指定される詳細のインジケーター レベルを使用してエラー メッセージを返します。

msgText = getReport(exception,type,'hyperlinks',hlink) は、hlink の値を使用して、実行できなかったコード行へのアクティブなハイパーリンクをエラー メッセージに含めるかどうかを決定します。

すべて折りたたむ

MATLAB に例外をスローさせます。

plus
Error using +
Not enough input arguments.

例外からエラー メッセージを取得します。

exception = MException.last;
msgText = getReport(exception)
msgText =

Error using +
Not enough input arguments.

現在の作業フォルダーのファイルで、testFunc.m 内に次の関数を作成します。

function a = testFunc
try
    a = notaFunction(5,6);
catch a

end

関数 notaFunction は存在しないため、testFuncMException オブジェクトを返します。

コマンド プロンプトで、testFunc を呼び出してエラー メッセージを取得します。

m = testFunc;
msgText = getReport(m)
msgText =

Undefined function 'notaFunction' for input arguments of type 'double'.

Error in testFunc (line 3)
    a = notaFunction(5,6);

エラー メッセージにエラー メッセージのみを含み、スタック情報は含まないように指定します。

msgText = getReport(m,'basic')
msgText =

Undefined function 'notaFunction' for input arguments of type 'double'.

MATLAB に例外をスローさせます。

try 
    surf
catch exception
end

例外からエラー メッセージを取得します。

msgText = getReport(exception)
msgText =

Error using surf (line 49)
Not enough input arguments.

surf.m へのアクティブなハイパーリンクを使用せずにエラー メッセージを取得します。

msgText = getReport(exception,'extended','hyperlinks','off')
msgText =

Error using surf (line 49)
Not enough input arguments.

入力引数

すべて折りたたむ

エラー メッセージを示す例外オブジェクト。スカラー MException オブジェクトとして指定します。

返されるメッセージの詳細インジケーター。'extended' または 'basic' として指定します。

typemsgText 詳細レベル
'extended' (既定)msgText には、行番号、エラー メッセージ、原因およびスタックの概要が含められます。適切なスタックを表示するには、MATLAB は最初に例外をスローしなければなりません。
'basic'msgText にはエラー メッセージが含められます。

拡張機能

スレッドベースの環境
MATLAB® の backgroundPool を使用してバックグラウンドでコードを実行するか、Parallel Computing Toolbox™ の ThreadPool を使用してコードを高速化します。

バージョン履歴

R2007b で導入