Error Handling

Gamma: Version 4.0
Prev | Chapter 5. Control Flow | Next

# 5.4. Error Handling

An error handler is a function that responds to an error. In general, when a program executes, the flow of control moves from one expression to the next, possibly passing into and out of function calls, and following branches and loops as necessary. If an error occurs, however, the flow of control will not move to the next expression, but will jump immediately to the most recently declared error handler, either through the `protect`/`unwind` or the `try`/`catch` constructs. These constructs are the two pairs of functions available in Gamma which allow for trapping and handling errors. See Tutorial II for more details.

The combination of signal handlers and error handlers can cause a program to jump to a predefined point at any time during its execution. An error can be explicitly caused by a call to the `error` function.

## 5.4.1. Situations that might cause Gamma to crash

Gamma is a very robust language, particularly in comparison to programming in C. However, the power and ease of use can sometimes lead a programmer to create situations that could crash the Gamma engine. Generally these are errors that would certainly have crashed a C program, and would be considered part of the debug cycle. The following list highlights some situations where care must be taken:

1. A call to `init_ipc` inside a timer or signal handling routine. You should call (`init_ipc`) once at the beginning of your program if at all.

2. Abuse of Photon widget resources. While care has been taken to minimize the risk of a crash by abusing the Photon widgets, the bottom line is that widgets are raw C structures with fairly complex manipulation functions. If you write a bad value into a C structure, your program will crash. If you fail to call `PtInit`, your program will crash. If you create a non-window widget with no parent, your program will crash. These are just facts of life.

3. Gamma provides a 'wrapper' for most of the standard C library functions that makes the corresponding C function call after extracting the Gamma arguments. If the arguments passed cause the C function to crash, then your program and the Gamma engine will crash as well.

Having said these things, we are always interested in hearing about new ways that we can make Gamma more robust. Please don't hesitate to let us know if you find a weak spot.

Prev | Home | Next
Event Handling | Up | Tutorial II

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.