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

try -- catch an error

Synopsis

Description

The return value is the value returned by y or z, as the case may be.

The clause 'then y' may be omitted, in which case the return value is the value returned by x, if there is no error or alarm.

The clauses 'then y else z' may both be omitted, in which case the return value is the value returned by x, unless an error or alarm occurs, in which case null is returned.

The behavior of interrupts (other than alarms) is unaffected.
i1 : apply(-3..3,i->try 1/i else infinity)

        1    1                   1  1
o1 = (- -, - -, -1, infinity, 1, -, -)
        3    2                   2  3

o1 : Sequence

Caveat

We will change the behavior of this function soon so that it will be possible to catch errors of a particular type. Meanwhile, users are recommended to use this function sparingly, if at all.

For the programmer

The object try is a keyword.