blob: f9a605653c68c0ebfdd03744f6e62d570d8b62e9 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstrad59c3892019-11-28 20:53:39 +01002 mixed catch(expr, expr, ...)
Zesstra715ec202025-07-09 22:18:31 +02003 mixed catch(expr, expr, ... ; modifiers)
MG Mud User88f12472016-06-24 23:31:02 +02004
Zesstra715ec202025-07-09 22:18:31 +02005DESCRIPTION
6 Evaluate the expressions. If there is no error, 0 is returned.
7 If there is an error, the evaluation of the expressions stops at
8 that point, and a string with the error message is returned.
MG Mud User88f12472016-06-24 23:31:02 +02009
Zesstra715ec202025-07-09 22:18:31 +020010 System error messages start with a leading '*', user-defined
11 error values (other than 0) as given to throw() and raise_error() are
12 returned as they are.
MG Mud User88f12472016-06-24 23:31:02 +020013
Zesstra715ec202025-07-09 22:18:31 +020014 If at the time the catch() is encountered less than
15 __CATCH_EVAL_COST__ eval ticks are left, a runtime error will be
16 thrown from inside the catch() (and thus caught like every other
17 error) and the expressions will not be executed. The 'reserve'
18 modifier can be used to reserve a different amount of eval ticks.
MG Mud User88f12472016-06-24 23:31:02 +020019
Zesstra715ec202025-07-09 22:18:31 +020020 The default behaviour of catch() can be changed using modifiers:
MG Mud User88f12472016-06-24 23:31:02 +020021
Zesstra715ec202025-07-09 22:18:31 +020022 'nolog': Normally, the caught error will be logged in the
23 error logs for easier debugging. With this
24 modifier, the log is suppressed.
MG Mud User88f12472016-06-24 23:31:02 +020025
Zesstra715ec202025-07-09 22:18:31 +020026 'publish': Normally, master::runtime_error() is not called
27 for a caught error. This modifier instructs
28 catch() to call it nevertheless.
MG Mud User88f12472016-06-24 23:31:02 +020029
Zesstra715ec202025-07-09 22:18:31 +020030 'reserve <expr>': The expression has to evaluate to a number
31 greater than 0 and is used to determine the amount
32 of eval ticks to reserve, instead of the default
33 of __CATCH_EVAL_COST__. The minimum required
34 are 2 * __MASTER_EVAL_COST__.
35 'limit <expr>': The expression has to evaluate to a number
36 greater than 0 and is used to limit the eval cost
37 for the evaluation of the expression.
MG Mud User88f12472016-06-24 23:31:02 +020038
Zesstra715ec202025-07-09 22:18:31 +020039 catch() itself is not expensive as far as execution time is
40 concerned: it is about the same as a intra-object function call.
MG Mud User88f12472016-06-24 23:31:02 +020041
Zesstra715ec202025-07-09 22:18:31 +020042 throw() is not very expensive either, but does include the
43 internal cleanup of several structures.
Zesstrad59c3892019-11-28 20:53:39 +010044
Zesstra715ec202025-07-09 22:18:31 +020045 Real runtime errors on the other hand are expensive regardless
46 of whether they are caught or not, as they include the generation
47 of the stack backtrace.
48
49 catch() is not really an efun but a compiler directive.
50
51EXAMPLES
MG Mud User88f12472016-06-24 23:31:02 +020052 object obj;
53 string err;
Zesstra715ec202025-07-09 22:18:31 +020054 if (err = catch(obj = clone_object("/foo/bar/baz")))
55 write("Cannot clone object, reason:"+err"+\n");
MG Mud User88f12472016-06-24 23:31:02 +020056
Zesstra715ec202025-07-09 22:18:31 +020057HISTORY
58 LDMud 3.2.9 introduced the 'nolog' catch() as experimental feature.
59 LDMud 3.2.10 implemented 'nolog' as official form and added
60 'publish'.
61 LDMud 3.3.559 moved the check regarding __CATCH_EVAL_COST__ inside
62 the catch().
63 LDMud 3.3.560 added the 'reserve' modifier.
64 LDMud 3.6.7 added the 'limit' modifier.
MG Mud User88f12472016-06-24 23:31:02 +020065
Zesstra715ec202025-07-09 22:18:31 +020066SEE ALSO
MG Mud User88f12472016-06-24 23:31:02 +020067 throw(E), raise_error(E), predefined(D), runtime_error(M)