Previous Page Next Page Contents

error -- raise a user-specified exception

Introduction

error(message) aborts the current procedure, returns to the interactive level, and displays the error message message.

Call(s)

error(message)

Parameters

message - the error message: a string

Side Effects

The formatting of the output of error is sensitive to the environment variable TEXTWIDTH.

Related Functions

lasterror, prog::error, traperror, warning

Details

Example 1

If the divisor of the following simple division routine is 0, then an error is raised:

>> mydivide := proc(n, d) begin
     if iszero(d) then
       error("Division by 0")
     end_if;
     n/d
   end_proc:
   mydivide(2, 0)
      Error: Division by 0 [mydivide]

Example 2

When the error is raised in the following procedure p, control is returned to the interactive level immediately. The second call to print is never executed. Note that the procedure's name is printed in the error message:

>> p := proc() begin
     print("entering procedure p");
     error("oops");
     print("leaving procedure p")
   end_proc:
   p()
                          "entering procedure p"
      Error: oops [p]

The following procedure q calls the procedure p and catches any error that is raised within p:

>> q := proc() begin
     print("entering procedure q");
     print("caught error: ", traperror(p()));
     print("leaving procedure q")
   end_proc:
   q()
                          "entering procedure q"
      
                          "entering procedure p"
      
                          "caught error: ", 1028
      
                           "leaving procedure q"

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000