ExceptionQ[expr]
gives True if expr is a valid Exception object, and False otherwise.
ExceptionQ[expr,tag]
gives True if expr is a valid Exception object of a subtype of tag.
ExceptionQ[expr,{tag1,tag2,…}]
gives True if expr is a valid Exception object of a subtype of any of tag1, tag2, ….
ExceptionQ
ExceptionQ[expr]
gives True if expr is a valid Exception object, and False otherwise.
ExceptionQ[expr,tag]
gives True if expr is a valid Exception object of a subtype of tag.
ExceptionQ[expr,{tag1,tag2,…}]
gives True if expr is a valid Exception object of a subtype of any of tag1, tag2, ….
Details
- The parent types in the second argument of ExceptionQ must be valid exception types (strings or symbols). They are not required to be registered exception types.
Examples
open all close allBasic Examples (1)
This tests for a valid Exception object:
ExceptionQ[Exception[tag]]The following expression is not a valid Exception object:
ExceptionQ[Exception[1, 2, 3]]This tests that the passed expression is a valid Exception object of type tag, or its subtypes:
ExceptionQ[Exception[tag], tag]Scope (2)
This registers the exception type as a child of some other exception type:
RegisterExceptionType[logicalError, "GeneralError"]This confirms that the passed expression is a valid Exception object of type "GeneralError":
ExceptionQ[Exception[logicalError, <|"Data" -> 42|>], "GeneralError"]This deregisters the exception type:
Unprotect[logicalError]
DeleteObject @ logicalErrorThis tests an unrelated Exception object, and the types do not match:
ExceptionQ[Exception[tag], "GeneralError"]For a list of types in the second argument of ExceptionQ, a single match is sufficient to give True:
ExceptionQ[Exception[tag], {tag, "GeneralError"}]Possible Issues (1)
This returns False, because ExceptionQ is applied to an unevaluated Exception constructor call:
ExceptionQ[Unevaluated @ Exception["SomeError"]]When applied to the fully evaluated Exception constructor, ExceptionQ produces True, as expected:
ExceptionQ[Exception["SomeError"]]Neat Examples (1)
This registers the exception type logicalError as a child of type "GeneralError":
RegisterExceptionType[logicalError, "GeneralError"]This defines the custom exception handler that rethrows exceptions of the type "GeneralError", and converts all other exceptions to Failure objects:
customHandler = Function @ With[{e = Exception @ #},
If[ExceptionQ[e, "GeneralError"], ThrowException @ e, e["ExceptionFailure"]]
]In this case, some generic exception is converted to a Failure:
CatchExceptions[All -> customHandler] @ ThrowException[SomeExceptionType, "abc"]In this case, exception of the type logicalError is rethrown, because logicalError is a subtype of "GeneralError":
CatchExceptions[All -> customHandler] @ ThrowException[logicalError, 42]Tech Notes
Related Guides
History
Text
Wolfram Research (2026), ExceptionQ, Wolfram Language function, 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: 12-June-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: 12-June-2026]}