ExceptionQ[expr]
ExceptionQ[expr,tag]
ExceptionQ[expr,{tag1,tag2,…}]
expr が tag1,tag2,… のいずれかのサブタイプである有効なExceptionオブジェクトである場合はTrueを返す.
ExceptionQ
ExceptionQ[expr]
ExceptionQ[expr,tag]
ExceptionQ[expr,{tag1,tag2,…}]
expr が tag1,tag2,… のいずれかのサブタイプである有効なExceptionオブジェクトである場合はTrueを返す.
詳細
- ExceptionQの第2引数の親タイプは,有効な例外タイプ(文字列またはシンボル)でなければならない.それらが登録された例外タイプである必要はない.
例題
すべて開く すべて閉じる例 (1)
スコープ (2)
RegisterExceptionType[logicalError, "GeneralError"]次は,渡された式がタイプ"GeneralError"の有効なExceptionオブジェクトであることを確認する:
ExceptionQ[Exception[logicalError, <|"Data" -> 42|>], "GeneralError"]Unprotect[logicalError]
DeleteObject @ logicalError次は,無関係なExceptionオブジェクトをテストするが,タイプは一致しない:
ExceptionQ[Exception[tag], "GeneralError"]ExceptionQの第2引数におけるタイプのリストについては,単一の一致があればTrueを返すのに十分である:
ExceptionQ[Exception[tag], {tag, "GeneralError"}]考えられる問題 (1)
ExceptionQが未評価のExceptionコンストラクタ呼出しに適用されるからので,以下はFalseを返す:
ExceptionQ[Unevaluated @ Exception["SomeError"]]完全に評価されたExceptionコンストラクタに適用すると,ExceptionQは予想どおりTrueを与える:
ExceptionQ[Exception["SomeError"]]おもしろい例題 (1)
次は,例外タイプlogicalErrorをタイプ"GeneralError"の子として登録する:
RegisterExceptionType[logicalError, "GeneralError"]次は,タイプが"GeneralError"である例外を再スローし,それ以外のすべての例外をFailureオブジェクトへ変換するカスタム例外ハンドラを定義する:
customHandler = Function @ With[{e = Exception @ #},
If[ExceptionQ[e, "GeneralError"], ThrowException @ e, e["ExceptionFailure"]]
]この場合,いくつかの汎用的な例外はFailureに変換される:
CatchExceptions[All -> customHandler] @ ThrowException[SomeExceptionType, "abc"]この場合,タイプlogicalErrorの例外が再スローされるのは,logicalErrorが"GeneralError"のサブタイプであるためである:
CatchExceptions[All -> customHandler] @ ThrowException[logicalError, 42]テクニカルノート
-
▪
- 例外の処理
関連するガイド
-
▪
- ロバスト性とエラー処理 ▪
- フロー制御 ▪
- パッケージの保護
テキスト
Wolfram Research (2026), ExceptionQ, Wolfram言語関数, https://reference.wolfram.com/language/ref/ExceptionQ.html.
CMS
Wolfram Language. 2026. "ExceptionQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ExceptionQ.html.
APA
Wolfram Language. (2026). ExceptionQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExceptionQ.html
BibTeX
@misc{reference.wolfram_2026_exceptionq, author="Wolfram Research", title="{ExceptionQ}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/ExceptionQ.html}", note=[Accessed: 23-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_exceptionq, organization={Wolfram Research}, title={ExceptionQ}, year={2026}, url={https://reference.wolfram.com/language/ref/ExceptionQ.html}, note=[Accessed: 23-September-2026]}