Sign in to follow this  

What happens when a function raises an exception?

This topic is 3866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

suppose I have a function like the one below that acts as a wrapper:
void WriteToLog(std::string message)
{
		TLog::GetInstance().LogMessage("Script",message,MSG_INFO);	
}

LogMessage raises a TFatalException on an error - ie: when the log file is not open. I will eventually change this to a TGenericException or the like which is nonfatal. But for the moment this is to be a fatal exception. So what happens if LogMessage raises an exception in its execution by AS? There is a catch wrapper outside of the main execution loop.
WinMain(...){
try
{
   ...
   SetupEngine();
   engine->Main();
   ...
}
catch(TFatalException &e)
{
    ShowError();
    Terminate();
}
}
And from engine->Main() is where the main while(1) lies, which in turn is calling out to the main AS function which could potentially call the Log function, which is where an exception could be raised. So - how do I handle this? or is there no need to worry? Cheers _S

Share this post


Link to post
Share on other sites
If you just want to log the error and then terminate the application, then you should be fine doing it the way you do.

But if you want to catch the exception and continue execution without memory leaks, then it's probably better to catch the exception already in the wrapper and instead call asIScriptContext::SetException() to tell AngelScript to end the script execution and clean up. The asIScriptContext::Execute() function will then return asEXECUTION_EXCEPTION (= 3).

Regards,
Andreas

Share this post


Link to post
Share on other sites

This topic is 3866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this