• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. Server-Side ActionScript > 6.5. Handling Errors with try/catch

Handling Errors with try/catch

Server-Side ActionScript contains the try/catch/finally construct of ECMAScript. If you have used JavaScript, Java, or ColdFusion before, you may be familiar with this construct, which is missing from client-side ActionScript. You use it like this:

try {
  // Code here
} catch(exception) {
  // Error handling code here
} finally {
  // Do this in either case
}

Tip

A try/catch/finally construct says, “Try to execute the code inside the try block. If there is an error (exception), execute the code in the catch block. In either case, execute the code in the finally block.”

To demonstrate, look at this SSAS code:

function getProducts ( ) {
  var sql = "SELECT ProductID, ProductName FROM Products";
  try {
    var myResults = CF.query("northwind", sql);
  } catch (e) {
    sendEmailAdmin(e);
    throw("There was an error connecting to the database");
  }
  return myResults;
}

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint