Previous Page Next Page Contents

traperror -- trap errors

Introduction

traperror(object) traps errors produced by the evaluation of object.

traperror(object, t) does the same. Moreover, it stops the evaluation if it is not finished after a real time of t seconds.

Call(s)

traperror(object)
traperror(object, t)

Parameters

object - any MuPAD object
t - the time limit: a nonnegative integer

Returns

a nonnegative integer.

Related Functions

error, prog::error, lasterror

Details

Example 1

Errors that happen during the execution of kernel functions have various error codes, depending on the problem. E.g., 'Division by zero' produces the error code 1025:

>> y := 1/x: traperror(subs(y, x = 0))
                                   1025
>> lasterror()
      Error: Division by zero [_power]

The following attempt to compute a huge floating point number fails because of numerical overflow. The corresponding error code is 20:

>> traperror(exp(12345678.9))
                                    20
>> lasterror()
      Error: Overflow/underflow in arithmetical operation;
      during evaluation of 'exp::float'

Example 2

All errors raised using the function error have the error code 1028. Errors during the execution of library functions are of this kind:

>> traperror(error("My error!"))
                                   1028
>> lasterror()
      Error: My error!

Example 3

We try to factor a polynomial, but give up after ten seconds:

>> traperror(factor(x^1000 + 4*x + 1), 10)
                                   1320
>> lasterror()
      Error: Execution time exceeded;
      during evaluation of 'faclib::univ_mod_gcd'

Example 4

Here we have two nested traperror calls. The inner call contains an unterminated loop and the outer call has a time limit of 2 seconds. When the execution time is exceeded, this special error is not trapped by the inner traperror call. Because of the error, print(1) is never executed:

>> traperror((traperror((while TRUE do 1 end)); print(1)), 2)
                                   1320
>> lasterror()
      Error: Execution time exceeded

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000