Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » error handling » Error
next | previous | forward | backward | up | index | toc

Error -- error information

Description

An instance of this class may be caught when an error occurs inside a trap or try statement. The error message may be recovered using toString and the location using locate.

i1 : (val, err) = trap 1/0

o1 = (, division by zero)

o1 : Sequence
i2 : toString err

o2 = division by zero
i3 : locate err

o3 = stdio:1:18-1:21

o3 : FilePosition

An Error object may be constructed from an error message.

i4 : err = new Error from "foo"

o4 = foo

o4 : Error

An error may be raised from an Error object using error.

i5 : stopIfError = false

o5 = false
i6 : error err
stdio:6:5:(3):[1]: error: foo

It is possible to create subclasses of Error for finer error handling.

i7 : MyError = new SelfInitializingType of Error

o7 = MyError

o7 : SelfInitializingType
i8 : try error MyError "bar" except err do err

o8 = bar

o8 : MyError

See also

Methods that use an error:

  • new Error from Thing
  • locate(Error) -- see locate -- locate source code

For the programmer

The object Error is a type, with ancestor class Thing.


The source of this document is in /build/reproducible-path/macaulay2-1.26.05+ds/M2/Macaulay2/packages/Macaulay2Doc/ov_debugging.m2:366:0.