Skip to main content
gamedev.net
🔒 Locked

Exception inside script code

Started by dxj19831029 1 reply 1.2k views
Original Post
dxj19831029
dxj19831029
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?
SiCrane
SiCrane
Unfortunately, AngelScript currently doesn't support handling exceptions in scripts, but it is on the list of things to do.
WitchLord
WitchLord
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 - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.