OverflowError

OverflowError()

The result of an expression is too large for the specified type and will cause a wraparound.

Examples

In the Julia programming language, the OverflowError() function is used to indicate that the result of an expression is too large for the specified type and will cause a wraparound.

Example:

julia> a = typemax(Int8) + 1
ERROR: OverflowError: attempt to add with overflow in checked context
Stacktrace:
 [1] checked_add(::Int8, ::Int64) at ./checked.jl:18
 [2] top-level scope at REPL[1]:1

In this example, we attempt to add 1 to the maximum value of the Int8 type. However, this operation would cause an integer overflow, and Julia raises an OverflowError to indicate the issue.

Common mistake example:

julia> a = typemax(Int64) + 1
-9223372036854775808

In this example, the user mistakenly assumes that overflowing the Int64 type will raise an OverflowError. However, Julia silently wraps around the value, and no error is raised. It's important to note that OverflowError is only raised in checked arithmetic contexts.

It's crucial to handle OverflowError appropriately to ensure accurate and safe computations.

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.

*Required Field
Details

Checking you are not a robot: