Using custom error handling

For use cases where you return additional information to the client as part of a message exception, you can use the extendedData property of the flex.messaging.MessageException class. This property is a HashMap, and provides a flexible way to return additional data to the client when a failure occurs. The Javadoc documentation in the docs directory of your Flex Data Services installation includes documentation for the flex.messaging.MessageException class.

NOTE

 

Flex Data Services serialization provides bean serialization of any Throwable type. This gives you the option of throwing your own Throwable exceptions with getters for the properties that you want to send to the client.

The following example shows a Java test class that adds extra data to an exception:

package errorhandling;

import java.util.HashMap;
import java.util.Map;
import flex.messaging.MessageException;

public class TestException {

public String generateMessageExceptionWithExtendedData(String extraData)
{       
    MessageException me = new MessageException("Testing extendedData.");
    Map extendedData = new HashMap();
        // The method that invokes this expects an "extraData" slot in 
// this map. extendedData.put("extraData", extraData); me.setExtendedData(extendedData); me.setCode("999"); me.setDetails("Some custom details."); throw me; } }

The following example shows an ActionScript method that generates an exception with extra data:

<?xml version="1.0"?>
<mx:Application 
        xmlns:mx="http://www.adobe.com/2006/mxml" 
        creationComplete="run()">

    <mx:RemoteObject
        destination="myDest"
        id="myException"
        fault="onServiceFault(event)"
/>
    <mx:Script>
    <![CDATA[
        import mx.rpc.events.*;
        import mx.messaging.messages.*;"

        public var data : String = "Extra data.";
        public var actualData : String;

        public function onServiceFault(event:FaultEvent):void {
            actualData = ErrorMessage(event.message).extendedData.extraData;
        }

        public function run_exception():void {
            var call : Object =
                myException.generateMessageExceptionWithExtendedData(data);
        }

        public function run():void {
            run_exception();
        }
    ]]>
    </mx:Script>
</mx:Application>

Flex 2.01

Take a survey


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/201/html/ent_services_config_097_21.html