Previous section To contents Next section

7.2 catch & throw

Catch is used to trap errors and other exceptions in Pike. It works by making a block of code into an expression, like this:
catch { statements }
If an error occurs, catch will return a description of the error. The description of the error has the following format:
({
     "error description",
     backtrace()
})
If no error occurs, catch will return zero. You may emulate your own errors using the function throw, described in
chapter 16 "Builtin functions".

Example:

int x,y;
// This might generate "division by zero"
mixed error=catch { x/=y; };


Previous section To contents Next section