<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="660" height="290" creationComplete="init()" viewSourceURL="srcview/index.html">
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.remoting.RemoteObject;
        
            private var exceptionGenService:RemoteObject;
            
            private function init():void
            {
                exceptionGenService = new RemoteObject( "GenericDestination" );
                exceptionGenService.source = "Weborb.Examples.ExceptionsTest";
                exceptionGenService.addEventListener( FaultEvent.FAULT, gotError );                                
            }
            
            private function gotError( fault:FaultEvent ):void
            {
                Alert.show( "Server reported an error - " + fault.fault.faultString );
                faultCodeField.text = fault.fault.faultCode;
                faultStringField.text = fault.fault.faultString;
                faultDetailField.text = fault.fault.faultDetail;
                nameField.text = fault.fault.name;
                messageField.text = fault.fault.message;
            }
            
        ]]>
    </mx:Script>
    <mx:Panel x="10" y="10" width="640" height="270" layout="absolute" title="Exception Handling Example">
        <mx:Button x="25.5" y="67" label="Generate Division by Zero" width="205" click="exceptionGenService.divByZero()"/>
        <mx:Button x="25.5" y="112" label="Generate NullPointerException" width="205" click="exceptionGenService.NPE()"/>
        <mx:Button x="25.5" y="158" label="Generate Application Exception" width="205" click="exceptionGenService.throwException()"/>
        <mx:TextArea x="20" y="20" width="216" height="43" textAlign="center" borderStyle="none">
            <mx:text>Click a button below to generate an exception on the server</mx:text>
        </mx:TextArea>
        <mx:Canvas x="263" y="20" width="345" height="199" borderStyle="solid">
            <mx:Text x="28" y="20" text="faultString:"/>
            <mx:Text x="28" y="57" text="faultDetail:"/>
            <mx:Text x="31" y="98" text="faultCode:"/>
            <mx:Text x="34" y="134" text="message:"/>
            <mx:Text x="53" y="169" text="name:"/>
            <mx:Label x="103" y="20" id="faultStringField" width="230"/>
            <mx:Label x="103" y="57" id="faultDetailField" width="230"/>
            <mx:Label x="103" y="98" id="faultCodeField" width="230"/>
            <mx:Label x="103" y="134" id="messageField" width="230"/>
            <mx:Label x="103" y="169" id="nameField" width="230"/>
        </mx:Canvas>
        <mx:Text x="273" y="11" text="Exception Details" opaqueBackground="0xffffff"/>
    </mx:Panel>
    
</mx:Application>