Jump to content
  • Advertisement
Sign in to follow this  
_Sigma

What happens when a function raises an exception?

This topic is 4170 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!