9 Replies Latest reply on Aug 23, 2012 10:19 AM by fgadotti

    Global Exception Handler

    fgadotti

      Hello,

       

      I've implemented the Global Exception Handler how is saying at http://www.adobe.com/devnet/flex/articles/global-exception-handling.html

      Some errors are being catched by it, and others not.

       

      I looked at another thread here, but for him, the Debug Dialog was not appearing because another place was catching the exception for him.

       

      There are some way to catch all errors in just on place?

       

      I need this, because sometimes in production happen errors that we didn't find in development, but stills there.

       

      The SDK is 4.1 and minimum Flash Player for the applications is 10.1.

       

      Regards,

       

      Fredy.

        • 1. Re: Global Exception Handler
          Flex harUI Adobe Employee

          Many times exceptions are thrown and caught as expected, and you shouldn’t need to care about them.  But if exceptions are thrown and the debugger shows the dialog, it may mean that you have other SWFs being loaded that are throwing errors.  See the post on my blog about uncaught errors in modules.

           

           

          --

          Alex Harui

          Flex SDK Team

          Adobe Systems, Inc.

          http://blogs.adobe.com/aharui

          • 2. Re: Global Exception Handler
            fgadotti Level 1

            How to reproduce the error not being catched.

             

            Main Application:

            <?xml version="1.0" encoding="utf-8"?>

            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                                             xmlns:s="library://ns.adobe.com/flex/spark"

                                             xmlns:mx="library://ns.adobe.com/flex/mx"

                                             minWidth="955"

                                             minHeight="600"

                                             xmlns:views="views.*"

                              applicationComplete="onApplicationComplete()">

             

             

                      <s:layout>

                                <s:VerticalLayout />

                      </s:layout>

             

                      <fx:Script>

                                <![CDATA[

                                          import com.adobe.ac.logging.GlobalExceptionHandler;

                                          import com.adobe.ac.logging.LogHandlerAction;

             

                                          private var globalExceptionHandler:GlobalExceptionHandler;

             

                                          private function onApplicationComplete():void {

                                                    globalExceptionHandler = new GlobalExceptionHandler();

                                                    globalExceptionHandler.preventDefault = true;

             

                                                    var lha:LogHandlerAction = new LogHandlerAction();

                                                    globalExceptionHandler.handlerActions = [];

                                                    globalExceptionHandler.handlerActions.push(lha);

                                          }

             

                                ]]>

                      </fx:Script>

             

                      <mx:ViewStack id="vs" creationPolicy="none">

                                <views:FirstView  />

                                <views:SecondView />

                      </mx:ViewStack>

             

                      <s:Button label="Call Second View" click="vs.createDeferredContent()"/>

            </s:Application>

            First View:

            <?xml version="1.0" encoding="utf-8"?>

            <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"

                                 xmlns:s="library://ns.adobe.com/flex/spark"

                                 xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"

                                 creationComplete="onCreationComplete()">

             

                      <fx:Script>

                                <![CDATA[

                                          import mx.rpc.remoting.RemoteObject;

             

                                          private function onCreationComplete():void {

                                                    trace("First Created!");

                                          }

             

                                ]]>

                      </fx:Script>

            </s:NavigatorContent>

             

            Second View:

            <?xml version="1.0" encoding="utf-8"?>

            <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                              xmlns:s="library://ns.adobe.com/flex/spark"

                                                              xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"

                                                              creationComplete="onCreationComplete()">

                      <fx:Script>

                                <![CDATA[

                                          import mx.rpc.remoting.RemoteObject;

             

                                          private function onCreationComplete():void {

                                                    trace("Second View created!");

             

                                                    var ro:RemoteObject;

             

                                                    ro.destination = "";

                                          }

             

                                ]]>

                      </fx:Script>

            </s:NavigatorContent>

             

             

            Regards,

             

            Fredy.

            • 3. Re: Global Exception Handler
              fgadotti Level 1

              In the beginning I thought could be some module throwing the exception. But I had forced the error and it wasn't catched at all.

               

              I posted a simple code that reproduce the error not being catched.

               

              Thanks for the answer.

               

              Regards,

               

              Fredy.

              • 4. Re: Global Exception Handler
                Flex harUI Adobe Employee

                What was the call stack for the error that was not caught?  In your example the handler is not set up until applicationComplete so anything that throws earlier than that will not get caught.

                • 5. Re: Global Exception Handler
                  fgadotti Level 1

                  I thought my example is correct.

                  The ApplicationComplete configure the handler, and the ViewStack has creationPolicy equals none. The content of the ViewStack is only created when I click at the button to create the deffered content.

                   

                  Here is the stack trace, the portuguese part is the null object message:

                   

                  TypeError: Error #1009: Não é possível acessar uma propriedade ou um método de uma referência de objeto nula.

                            at views::SecondView/onCreationComplete()[C:\SMED\tags\sw_Pacote8_Piloto\flex\sismed\GlobalE xceptionHandlerProject\src\views\SecondView.mxml:15]

                            at views::SecondView/___SecondView_NavigatorContent1_creationComplete()[C:\SMED\tags\sw_Paco te8_Piloto\flex\sismed\GlobalExceptionHandlerProject\src\views\SecondView.mxml:5]

                            at flash.events::EventDispatcher/dispatchEventFunction()

                            at flash.events::EventDispatcher/dispatchEvent()

                            at mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\core \UIComponent.as:12528]

                            at mx.core::UIComponent/set initialized()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:1627]

                            at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framewo rk\src\mx\managers\LayoutManager.as:759]

                            at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects \framework\src\mx\managers\LayoutManager.as:1072]

                   

                  Regards,

                   

                  Fredy.

                  • 6. Re: Global Exception Handler
                    Flex harUI Adobe Employee

                    Are you using RSLs or modules?  Maybe you aren’t implementing the GlobalExceptionHandler properly?  I’ve never used that class, I just code up a low-level handler.

                    • 7. Re: Global Exception Handler
                      fgadotti Level 1

                      I'm using the framwork linkage as the SDK default ( RSL ). Excepted by that, there are no other RSL.

                      The SDK version is 4.1.

                       

                      My implementation is just like the one found at http://www.adobe.com/devnet/flex/articles/global-exception-handling.html

                      I don't know what else I can try to fix that.

                       

                      Regards,

                       

                      Fredy.

                      • 8. Re: Global Exception Handler
                        Flex harUI Adobe Employee

                        Try using the merged-into-code option so all code involved is in one SWF.

                        • 9. Re: Global Exception Handler
                          fgadotti Level 1

                          Thanks Alex

                          I've tested and now is catching all errors.

                          Just had a few problems with my skins but I'm fixing it now.

                           

                          Regards,

                           

                          Fredy.