Skip to main content
GameDev.net gamedev.net
🔒 Locked

Try/Catch Support

Started by Jason Goepel Dec 3, 2018 at 4:42 PM 1 replies 2.6k views
Original Post
Jason Goepel
Jason Goepel

I noticed this in the 2.33.0 WIP page:

"Added support for try/catch statements"

I'm sure you will elaborate the feature in the documentation, but I was curious if this "try/catch" behavior was going to include "throw" statements? If so, would the "catch" statement be able to catch a specific kind of exception? Could there be some sort of variable or function accessible from the "catch" statement that could contain information about the exception?

Thank you

WitchLord
WitchLord

I've opted for a quite simple solution. The compiler/VM only has a simple try/catch statement to capture any exception and unwind the stack.

The application can then register its own methods for throwing exceptions explicitly and for inspecting caught exceptions. The standard add-on of course come with a couple of pre-implemented solutions that the applications can use if you prefer not to implement your own.

Here's the excerpt from the doxygen source for the WIP version:




\section try Try-catch blocks

 {
   try
   {
     DoSomethingThatMightThrowException();
  
     // This is not executed if an exception was thrown
   }
   catch
   {
     // This is executed if an exception was thrown
   }
  }
A try-catch block can be used if you're executing some code that might throw an exception and you want to catch that exception and continue with the exception rather than just abort the script. \subsection try_func Functions \note The standard throw and getExceptionInfo are only provided if the application \ref doc_addon_helpers_try "registers them". void throw(const string ∈ exception) Explicitly throw an exception. The string should identify the type of exception, for logging or treating. string getExceptionInfo() Get the exception string for the last exception thrown.


One enhancement over the standard add-on that I can think of is to allow the throw and getExceptionInfo carry a dictionary with further information on the exception, e.g. location, callstack, and perhaps user defined parameters.


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.