7 Replies Latest reply on Sep 29, 2010 6:29 AM by BhaskerChari

    how can you handle throw exception

    Magesh R

      Hi Friends,

       

       

           My Server application is coldfusion .In  my coldfusion site i throw exception during file upload ..These Exception  ,how can u handle (or catch ) in  my flex Application site...

       

      please any one Help to me.

       

                               For example i give some sample code

       

        ColdFusion Code :

       

             
      <cftry>

           .......//file upload code there
      <cfcatch type="any" >
      <cfthrow type="Invalid" message="#cfcatch.message#">
      </cfcatch>

       

      Fex Code:

       

      fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);     
      fileReference.upload(urlReq);

       

      function uploadCompleteHandler(event:Event):void
      {

      Alert.show(event.target.name,"ALert");
      }

       

       

      Thanks,

      Magesh R.

        • 1. Re: how can you handle throw exception
          rootsounds Level 4

          An IOError event is dispatched when the upload fails.

          • 2. Re: how can you handle throw exception
            Magesh R Level 1

            Hi Firends,

             

             

            fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler); 

            fileReference.addEventListener(IOErrorEvent.IO_ERROR,uploadIOErrorHandler);
            fileReference.upload(urlReq);


            function uploadCompleteHandler(event:Event):void
            {
                
                 Alert.show(event.target.name,"ALert");
            }
              

            function uploadIOErrorHandler(event:IOErrorEvent):void
            {
                 var evt:IOErrorEvent = new IOErrorEvent("uploadIoError", false,false,event.text);
                 dispatchEvent(evt);
            }

             

            it will be always excute uploadCompleteHandler fuunction only not in uploadIOErrorHandler function.

             

             

            Thanks,

            Magesh R.

            • 3. Re: how can you handle throw exception
              rootsounds Level 4

              My guess would be that ColdFusion is sending out the incorrect HTTP status code on the exception.

              • 4. Re: how can you handle throw exception
                Magesh R Level 1

                Hi Firend,

                 

                 

                I already checked in coldfusion throw statement  in coldfusion site.  it will be correct...that's way i throw the exception to flex...but i don't know how can you  handle in flex site.

                 

                 

                Thanks,

                Magesh R.

                • 5. Re: how can you handle throw exception
                  rootsounds Level 4

                  I get that the exception is thrown, but I think that based on the described behavior that there is the possibility that the HTTP response status code is not being set to reflect this failure and is instead reporting success. My guess is that the dispatching of the Complete or IOError events is based on the status code returned.

                   

                  Server-side exceptions only have meaning on the server. For example, I've dealt with Java web services that fail with an exception but incorrectly return a status code of 201 (OK).

                  • 6. Re: how can you handle throw exception
                    Magesh R Level 1

                    Is there any other way to catch the exception in the flex other than IOError Event handler (which is not working)? Please note upload is happening successfully, but we want to throw a different exception in coldfusion and catch it in the flex ( while doing upload)

                     

                    Following is the coldfusion code :

                     

                    <cfcatch type="any" >
                    <cfthrow type="Invalid" message="#cfcatch.message#">

                    </cfcatch>

                     

                     

                    Following is the flex code that does not catch the exception :


                    fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);

                    fileReference.addEventListener(IOErrorEvent.IO_ERROR,uploadIOErrorHand ler);
                    fileReference.upload(urlReq);


                    function uploadCompleteHandler(event:Event):void
                    {
                        
                         Alert.show(event.target.name,"ALert");
                    }
                     

                    function uploadIOErrorHandler(event:IOErrorEvent):void
                    {
                         var evt:IOErrorEvent = new IOErrorEvent("uploadIoError", false,false,event.text);
                         dispatchEvent(evt);
                    }

                     

                    Thanks in advance.

                    • 7. Re: how can you handle throw exception
                      BhaskerChari Level 4

                      Hi Magesh R,

                       

                      I think you are throwing your custom exceptions from the ColdFusion..Am I right...??

                       

                      I dont think by  throwing custom exceptions from the ColdFusion you will able to catch that in uploadIOErrorHandler().

                       

                      For that type of exceptions uploadCompleteHandler() only gets called ...so if you want to throw and alert you can check for the message in result Event parameter and check the condition.

                       

                      Only the exceptions which are thrown by default such as invalid destination url or Security concerns something like that may be caught in the IOErrorEvent.IO_ERROR handler but not your custom exceptions. So check for the error message in the uploadCompleteHandler() itself.

                       

                      Thanks,

                      Bhasker