ODBiC Discussion Board

RE: Problem with reserved words in variables - can you suppress errors?, David Richardson, 07-16-2009

You can use the $varstr( ) function

by Roger Harris, July 16, 2009 14:20

The $varstr( ) function doesn't really do anything except to suppress replacing variables and functions in a string. It's useful for cases where you have actual variable names in a string but you don't want them to be evaluated until later in the processing, or for any strings that coincidentally have things that look like variables or functions but they are not.

Variables and functions are evaluated each time a string is output or used in any expression, so you may still want to replace any $ characters with #36 rather than find all the places where you would need to handle it. So, $repl($varstr($line$),"$"="& #36;") should do the replacement without producing any errors.

But there is also a general way to suppress or otherwise handle script errors: The ONERR statement lets you define an error handler script, i.e. a block of statements ended by the ENDERR statement, which will be executed each time any script error is encountered. The detected error will be in the variable $odbic_error$. You can do any normal commands in the script (but note that errors in the script itself will be ignored, to avoid an endless recursion loop). If $odbic_error$ still has a value when the script finishes at the ENDERR statement (which could be a new value that you set in the script rather than the original message), then it will be output in the usual error message format. However, if you reset $odbic_error$ to an empty string in the script, then ODBscript will not output any error message. So, a script to simply suppress any error messages would be:

SET odbic_error="";
I sometimes use the following script in cases where there are can be errors that are "expected" and not serious, but you don't really want them completely ignored in case something unexpected should happen. It just puts any errors in an HTML comment rather than the displayed text, so you can still see them if you view the source, but they don't muck up the page or confuse users:
<% ONERR %>
<!-- Script error: $odbic_error$ -->
<% SET odbic_error=""; ENDERR %>


Post Your Reply:

E-mail  optional

HTTP Link: 
Link text: 


Copyright ©1997-2003, Roger Harris. All rights reserved.