mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
* Error -> Defect for defects The distinction between Error and Defect is subjective, context-dependent and somewhat arbitrary, so when looking at an exception, it's hard to guess what it is - this happens often when looking at a `raises` list _without_ opening the corresponding definition and digging through layers of inheritance. With the help of a little consistency in naming, it's at least possible to start disentangling the two error types and the standard lib can set a good example here.
28 lines
937 B
Nim
28 lines
937 B
Nim
discard """
|
|
action: run
|
|
"""
|
|
|
|
doAssertRaises(OverflowDefect): discard low(int8) - 1'i8
|
|
doAssertRaises(OverflowDefect): discard high(int8) + 1'i8
|
|
doAssertRaises(OverflowDefect): discard abs(low(int8))
|
|
doAssertRaises(DivByZeroDefect): discard 1 mod 0
|
|
doAssertRaises(DivByZeroDefect): discard 1 div 0
|
|
doAssertRaises(OverflowDefect): discard low(int8) div -1'i8
|
|
|
|
doAssertRaises(OverflowDefect): discard -low(int64)
|
|
doAssertRaises(OverflowDefect): discard low(int64) - 1'i64
|
|
doAssertRaises(OverflowDefect): discard high(int64) + 1'i64
|
|
|
|
type E = enum eA, eB
|
|
doAssertRaises(OverflowDefect): discard eA.pred
|
|
doAssertRaises(OverflowDefect): discard eB.succ
|
|
|
|
doAssertRaises(OverflowDefect): discard low(int8) * -1
|
|
doAssertRaises(OverflowDefect): discard low(int64) * -1
|
|
doAssertRaises(OverflowDefect): discard high(int8) * 2
|
|
doAssertRaises(OverflowDefect): discard high(int64) * 2
|
|
|
|
doAssert abs(-1) == 1
|
|
doAssert 2 div 2 == 1
|
|
doAssert 2 * 3 == 6
|