error
エラーメッセージ
呼出し手順
error(message) error(message, n) error(n, message)
引数
- message
- 文字列または文字列のベクトル. 表示されるエラーメッセージ. 
- n
- 整数. エラーメッセージの番号 
説明
error 関数によりエラーメッセージを発行でき,
            エラーを処理できます.
            デフォルトで error は実行を停止し,
            プロンプトレベルに復帰します.
            このデフォルト動作は,errcatch または
            execstr(…,'errcatch') 関数により変更できます.
error(message) はmessageの文字列を
            出力します. エラーメッセージの番号は 10000 となります.
error(message,n) は
            messageの文字列を出力します.
            エラーメッセージの番号はnで指定されます.
エラーメッセージのリストおよび対応するエラー番号については error_table を参照ください.
例
function test(a) if argn(2)~=1 msg = gettext("%s: Wrong number of input arguments: %d expected.\n") error(msprintf(msg, "test", 1)) end endfunction function myfun() a = 1; test() endfunction // ---------- error(['A multi line' 'error message']) error(500, 'Error: my error message') [m, n] = lasterror() test() myfun()
--> error(['A multi line' 'error message']) A multi line error message --> error(500, 'Error: my error message') Error: my error message --> [m, n] = lasterror() n = 500. m = Error: my error message --> test() 関数の 4 行目 test test: 入力引数の数が間違っています: 1 個の引数を指定してください. --> myfun() 関数の 4 行目 test 関数の 3 行目 myfun test: 入力引数の数が間違っています: 1 個の引数を指定してください.
参照
履歴
| バージョン | 記述 | 
| 5.0.0 | error(n, message)syntax introduced. | 
| 5.4.0 | error関数は入力引数として文字列ベクトルを受け付けます. | 
| 6.0.0 | The error(n)anderror(n, pos)syntaxes
                    are no longer supported: Providing an explicit error message is now mandatory.
                    There is no longer any absolute error identifier. | 
| Report an issue | ||
| << errclear | Error handling | error_table >> |