Jump to content
  • Advertisement
Jason Goepel

Try/Catch Support

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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

<pre>
 {
   try
   {
     DoSomethingThatMightThrowException();
  
     // This is not executed if an exception was thrown
   }
   catch
   {
     // This is executed if an exception was thrown
   }
  }
</pre>

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 <tt>throw</tt> and <tt>getExceptionInfo</tt> are only 
provided if the application \ref doc_addon_helpers_try "registers them". 

<b>void throw(const string &in exception)</b>

Explicitly throw an exception. The string should identify the type of exception, for logging or treating.

<b>string getExceptionInfo()</b>

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.

 

Share this post


Link to post
Share on other sites

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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!