Handling exceptions from FRE* functions

Welcome to another short tutorial from our Translating between ActionScript and Objective-C series. I’ve lined up an exceptional article for you.

… which is mostly to say that today we will be dealing with exceptions.

What was covered so far?

What will this part cover?

Today’s addition to your library of auxiliary functions looks like this:

What does it do for you? A lot of the AIR C API functions can throw exceptions, but not the traditional way. Instead of immediately stopping the flow of code, exceptions are “returned” as output parameters. For example, the FRESetObjectProperty function takes a pointer to an exception object (FREObject, really), in which to put exception information, should an exception occur:

This exception object, being hidden behind a FREObject (see this post for a detailed look behind the curtain of the FREObject), will need some processing before it can tell you what happened. The auxiliary function you are implementing today will do that for you and save you the need to do a lot of multiline checks after each AIR API call in your native iOS code.

Wait. What’s an exception?

If you are new to exceptions: you can think of an exception as an event. When thrown or dispatched, it disrupts the normal flow of code. For example: if a call to AIR in the middle of one of your functions throws an exception, the rest of the code in that function will not be executed. Execution will instead be
passed to an exception handler if one is found in your function or the function that called it or the function that called the one that called it… If no exception handler is found, your app will likely be terminated. An exception handler is usually implemented as a try-catch statement.

The implementation

Ass you will see, getting information about the exception takes a few lines of code, which you probably don’t want to repeat over and over either. The hasThrownException auxiliary function below will save you the need to. It checks if an exception was indeed thrown and if one was, tries to get information about it and pass it back to ActionScript:

Result

Instead of performing all of these checks after every AIR C API call in your native code, you now have a one-liner call that will do it for you. Check the next article on setting ActionScript object properties in your native code to see examples of how to use it.

What’s next?

Info: For a comprehensive data conversion guide and how to make it into a library download our eBook “iOS vs. ActionScript Data Types Guide”.

Warning: count(): Parameter must be an array or an object that implements Countable in /home/easyna6/public_html/easynativeextensions_wp/wp-includes/class-wp-comment-query.php on line 399

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">