CheckedArithmetic.@checked
— Macro@checked expr
Perform all the operations in expr
using checked arithmetic.
Examples
julia> 0xff + 0x10 # operation that overflows
0x0f
julia> @checked 0xff + 0x10
ERROR: OverflowError: 255 + 16 overflowed for type UInt8
You can also wrap method definitions (or blocks of code) in @checked
:
julia> plus(x, y) = x + y; minus(x, y) = x - y
minus (generic function with 1 method)
julia> @show plus(0xff, 0x10) minus(0x10, 0x20);
plus(0xff, 0x10) = 0x0f
minus(0x10, 0x20) = 0xf0
julia> @checked (plus(x, y) = x + y; minus(x, y) = x - y)
minus (generic function with 1 method)
julia> plus(0xff, 0x10)
ERROR: OverflowError: 255 + 16 overflowed for type UInt8
julia> minus(0x10, 0x20)
ERROR: OverflowError: 16 - 32 overflowed for type UInt8