Custom Java Exceptions, BlazeDS and Flex

April 7th, 2011 by Dave Turner

Here is a quick and dirty way to get flex to play well with Custom Java Exceptions

Custom Java exception
A Simple Java exception that adds a new field called customDetails (via a Bean Property)

public class myCustomException extends RuntimeException {

  private static final long serialVersionUID = 1L;
  private String details;
  public CampaignSaveException(String arg0) {
    super(arg0);
    details = arg0;
  }

  public String getCustomDetails(){
    return details;
  }
}

When Java throws this exception during a remote call (i.e..)

  throw new myCustomException ("Details for the error message");

I can use this method to identify that this is in fact a myCustomException exception by looking for properties relevant to that class. This gives me an option to do some conditional logic when handling exceptions.

Note the usage of the “Bean property” where getCustomDetails() is set in the Java class but referenced in the front end as errorMessage.rootCause.customDetails.

private function onSaveError(event:FaultEvent):void
{
  var errorMessage:ErrorMessage = event.message as ErrorMessage;
  if(errorMessage.rootCause.customDetails != null)
    Alert.show(errorMessage.rootCause.customDetails, "", Alert.OK);
  else{
    Alert.show("Generic Error Message", "", Alert.OK);
  }
}

I believe there are more advanced methods than looking for a “bean property” (maybe casting?) but as the title suggests this is a quick and dirty example. Looking over the BlazeDS documentation

http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=serialize_data_2.html.

 

It doesn’t look like BlazeDS will map Custom Java Exceptions to Flex Exceptions .. So i think there’s always going to be a little bit of hackery to any implementation of passing and handling exceptions between Java and Flex.

ant mxmlc java heap space error

May 10th, 2010 by Dave Turner

Fix for ant mxmlc java heap space error

When compiling large Flex apps via ant on crappy machines (like the one my job provides me) You may get a Java out of memory heap error.

I got past this by doing the following

In Eclipse
1. Open up the ant “run as” dialog box
2. go the JVM tab and add the following argument to the JVM arguments section “-Xmx512M”

In Ant from the command line
1. set ANT_OPTS= -Xmx512M

set ANT_OPTS=-Xmx512M; export ANT_OPTS

Hope this helps