AssertionError
AssertionError([msg])
The asserted condition did not evalutate to true.
Optional argument msg is a descriptive error string.
Examples
-
Throw a basic assertion error:
julia> assert(false, "This is an assertion error") ERROR: AssertionError: This is an assertion errorThis example throws an
AssertionErrorwith the provided error message when the conditionfalseis evaluated. -
Assert inequality using an error message:
julia> x = 5 5 julia> assert(x != 5, "x should not be equal to 5") ERROR: AssertionError: x should not be equal to 5In this example, an
AssertionErroris thrown with the given error message if the conditionx != 5is not satisfied. -
Assert a condition without an error message:
julia> assert(2 + 2 == 5) ERROR: AssertionErrorThis example throws a basic
AssertionErrorwhen the condition2 + 2 == 5is not true.
Common mistake example:
julia> assert(1 == 2, "This should fail")
ERROR: AssertionError: This should fail
In this example, the condition 1 == 2 is expected to be false, but it evaluates to true. Double-check that the condition used in the assert statement is correct to avoid such mistakes.
See Also
ArgumentError, AssertionError, BoundsError, DivideError, DomainError, EOFError, error, ErrorException, InexactError, InitError, KeyError, LoadError, MethodError, OutOfMemoryError, OverflowError, ParseError, ReadOnlyMemoryError, showerror, StackOverflowError, SystemError, TypeError, UndefRefError, UndefVarError,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.