a wob"if_error"=error_object
When the if_error argument of a try is executed, a local variable named
error_object
is bound to the string of the error message that was created by executing
the attributes to try.
<try if_error="This call had: ".<join error_object/> >
234
<error "busted"/>
567
</try> | "This call had: Runtime error:
busted" |
If the body of a call to 'try' causes an error, try executes the code
up to the error in the body, and, with no if_error argument, just
returns null without erroring.
Example: No if_error argument
<try>
<error "got an e"/>
</try>
 | null |
Since the call to try above doesn't actally error, any code after the
call to try will be executed.
<do
<try>
<error "got an e"/>
</try>
33
/>
 | 33 |
If you want to return the "error_object" (which is just string), you can:
Example: Return the error object.
<try if_error=error_object>
<error "got an e"/>
</try>
 | "Runtime error: got an e" |
Beware, though, that the call to try does not result in an error,
and processing continues on after the call to try:
<do
<try if_error=error_object>
<error "got an e"/>
</try>
33
/> | 33 |
If what you're after is to call the try and have it error when its content errors:
<do
<try if_error=<error error_object/>>
<error "got an e"/>
</try>
33
/> | error |
The above code is the same as:
<do <error "got an e"/> 33/>
error
So you wouldn't bother using the try at all.
More likely though, is that you'd want to do something before
causing the error in the if_error argument.
You might want to write some 'clean-up' code before erroring.
Here we simulate our clean-up code with an echo statement:
<do
<try if_error=<do <echo "cleanup 'got an e' error"/>
<error error_object/>
/>
>
<error "got an e"/>
</try>
33
/> | error |
If you want to protect against the if_error argument of a try call causing an error,
wrap another try statement all around your original call to try.
busted
Here's the order of execution above:
- 123 is executed
<error "a bug"/> is executed causing an error.<error "some code that errors"/> is executed- "busted" is executed.
© Copyright 2007 Clear Methods, Inc.