Advertisement

Exception inside script code

Started by August 05, 2009 10:02 PM
1 comment, last by WitchLord 15 years, 6 months ago
Does the angelscript code support throw exception and handle the exception? let's say (script code):


try {
  object.fireExeption();
} catch {
  // doing something
}

I don't want to handle the exception inside C++ code, so does angelscript support it? any plan?
Unfortunately, AngelScript currently doesn't support handling exceptions in scripts, but it is on the list of things to do.
Advertisement
You can throw exceptions by registering a function like this:

void ThrowScriptException(const string &msg){  asIScriptContext *ctx = asGetActiveContext();  ctx->SetException(msg.c_str());}


However, it is not yet possible to catch the exception from within the scripts.

When an exception is thrown like this the context will immediately return from the Execute() method with the code asEXECUTION_EXCEPTION. The application can then examine the stack trace and values of variables if desired, but cannot resume the execution.

When the context is reused or released the stack will be cleaned up so no memory leaks will occur.

Catching exception from within the scripts is on the to-do list as SiCrane mentioned, but it is rather low priority at the moment. However, if anyone feels up to implement that support for me I'd gladly add it to the library.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement