Sambar Server Documentation

CScript Try/Catch Blocks


Cscript implements the C++ try...catch functionality to simplify writing large blocks of code. In traditional C coding, each function call must be tested for success or failure and some bugs (for example, runtime errors) cannot be handled at all. CScript allows code to be wrapped in a try/catch block to handle fatal errors gracefully:
<html> <body> <% try { code here... } catch (e) { printf("A fatal error prevents us from doing X\n"); } %> </body> </html>

You can throw your own exceptions from inside functions to exit to the catch block as well:
<html> <body> <% foo(int a) { throw("Oops, it didn't work"); } try { foo(123); } catch (e) { printf("Fatal Exception: %s\n", cs_exception(e)); } %> </body> </html>

© 2001 Sambar Technologies. All rights reserved. Terms of Use.