HTML/CSS Service

Showcase

2 comments0 views
1 Star2 Stars

Flex Error Handling Example

Category: Flex Error    |    2,783 views    |    2 Comments

 

This example is associated with the blog “Dustin’s Software
Cogitations and Speculations.”

The Flash Players, regular and debugger, can be downloaded
at http://www.adobe.com/support/flashplayer/downloads.html. –>

<mx:Script>
import mx.utils.ObjectUtil;

/**
* Test Flex exception handling.
*/
public function testException():void
{
try
{
intentionallyThrowException();
}
catch (error:Error)
{
stackTraceText.text = ObjectUtil.toString(error.getStackTrace());
messageText.text = error.message;
toStringText.text = error.toString();
nameText.text = error.name;
errorIdText.text = String(error.errorID);
}
finally
{
// I get called whether an exception is caught or not.
}
}

/**
* Intentionally throw an exception for use in Flex exception
* testing.
*/
public function intentionallyThrowException():void
{
throw new SyntaxError(”That was some bad syntax!”);
}
</mx:Script>

<mx:VBox id=”mainDisplay”>
<mx:Form>
<mx:FormItem id=”stackTraceItem” label=”Exception Stack Trace”>
<mx:Text id=”stackTraceText” />
</mx:FormItem>
<mx:FormItem id=”messageItem” label=”Message”>
<mx:Text id=”messageText” />
</mx:FormItem>
<mx:FormItem id=”toStringItem” label=”toString”>
<mx:Text id=”toStringText” />
</mx:FormItem>
<mx:FormItem id=”nameItem” label=”Name”>
<mx:Text id=”nameText” />
</mx:FormItem>
<mx:FormItem id=”errorIdItem” label=”Error ID”>
<mx:Text id=”errorIdText” />
</mx:FormItem>
</mx:Form>
</mx:VBox>

</mx:Application>

A significant portion of the above code is actually comments. If you remove the explanatory comments, the code is pretty small. Either way, the code is straightforward, especially if you have written Java exception handling code before. Read more…

Share/Save/Bookmark

 

Exception Handling with BlazeDS and Flex

Category: Flex Error    |    2,266 views    |    2 Comments

 

Create a Java Class that extends RuntimeException.

package com.flex3.exception;
public class FlexException extends RuntimeException
{
public FlexException(String message)
{
super(message);
}
}

2. Create a matching flex class called FlexException, and put the usual RemoteObject tag in their so BlazeDS will know what to look for. Also remember in actionscript, each object must be instantiated at least once, so be sure to do that somewhere with FlexException.

3. In Java, whenever there is a known exception, or some error where the end user needs to be shown a message, throw a FlexException and pass in the message the user should see in the constructor. Let’s say the user just entered an invalid password. throw new FlexException(”Wrong Password Entered, Please Try Again.”); Read more…

Share/Save/Bookmark

 

Exception Handling

Category: Flex Error    |    642 views    |    Add a Comment

 

Exceptions

Table of Contents

10.1. The Exception-Handling Cycle
10.2. Handling Multiple Types of Exceptions
10.2.1. Determining Exception Type Granularity
10.3. Exception Bubbling
10.3.1. Uncaught Exceptions
10.4. The finally Block
10.5. Nested Exceptions
10.5.1. A Nested Exception Bug
10.6. Control Flow Changes in try/catch/finally
10.7. Limitations of Exception Handling in ActionScript 2.0
10.7.1. No Checked Exceptions
10.7.2. No Built-in Exceptions
10.7.3. Exception Performance Issues
10.8. From Concepts to Code

Throughout this book, we’ve encountered plenty of compile-time errors—errors reported in the Output panel when a movie is exported. If a compile-time error occurs in an ActionScript 2.0 program, compilation fails and Flash won’t generate a .swf file to execute. But not all ActionScript errors occur at compile time. Some errors don’t occur until runtime, and they may not cause the program to fail completely. For example, suppose we attempt to load an XML file from disk, but the file is not found. If the movie is running in Test Movie mode, the failed load causes the Output panel to display an error message—but the movie continues to run. The following code demonstrates:

 

// If the specified file doesn’t exist… var xmlDoc:XML = new XML( ); xmlDoc.load(“http://www.somenonexistentsite.com/someNonExistentFile.xml”);

// …the Output panel displays: Error opening URL “http://www.somenonexistentsite.com/someNonExistentFile.xml”

 

In an ideal world, we’d like to be able to recover from nonfatal error conditions such as a file-not-found. We’d like to tell the user there was a problem loading the file and perhaps display the problematic filename.

Unfortunately, in ActionScript there are precious few built-in runtime errors and, what’s worse, there’s no standard error-handling mechanism for dealing with the errors that do occur at runtime—at least, not for the errors that are generated by ActionScript itself. Most errors in ActionScript occur in the form of custom error codes and return values. For example, a method might return the value -1, false, or nullto indicate that some operation failed. This requires us to write different, individualized code for each kind of error generated by ActionScript. Read more…

Share/Save/Bookmark