0 Replies Latest reply on Sep 12, 2006 11:44 AM by Duster_IDF

    Debug player ignores try/catch

    Duster_IDF
      In the following example, a try/catch block is ignored by the debug player (version 9,0,16,0).

      There is something about the combination of BindUtils#bindSetter() and function closures that causes this problem in the player.
      The function #trycatch() should catch the IllegalOperationError thrown by the argument function, but it doesn't. Instead the error is caught by the player - the try/catch block is simply ignored.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      creationComplete="testUpdate()"
      xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Script>
      <![CDATA[
      import mx.binding.utils.ChangeWatcher;
      import mx.binding.utils.BindingUtils;

      public var isActive:Boolean = false;

      [Bindable]
      public var comment:String = "";

      public function trycatch(tester:Function):void
      {
      try {
      trace("testingflex");
      //tester.apply(this); // not OK - try/catch is ignored & player catches the error
      tester(); // not OK - try/catch is ignored & player catches the error
      trace("flexdone");
      }
      catch (e:Error) {
      trace("caught:", e);
      }
      }

      public function onChange(aValue:Object):void {
      if (this.isActive) {
      trace("onChange before throw:", aValue);
      throw new IllegalOperationError("test");
      trace("onChange after throw");
      }
      }

      public function testUpdate():void {

      BindingUtils.bindSetter(onChange, this, "comment");

      this.isActive = true;

      trycatch(function():void {comment = "sample1"});
      }

      ]]>
      </mx:Script>

      </mx:Application>


      When running the example, the trace should look like:
      testingflex
      onChange before throw: sample1
      flexdone

      and there should not be any intervention by the debug player. However, the debug player shows its error window before the last line is traced.

      The player's trace window output:
      Error: test
      at Trycatch/onChange()[flex\Trycatch.mxml:32]
      at ()[C:\dev\GMC\sdk\frameworks\mx\binding\utils\BindingUtils.as:133]
      at mx.binding.utils::ChangeWatcher/mx.binding.utils:ChangeWatcher::wrapHandler()[C:\dev\GMC\ sdk\frameworks\mx\binding\utils\ChangeWatcher.as:418]
      at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at Trycatch/set comment()[flex\Trycatch.mxml:14]
      at ()[flex\Trycatch.mxml:43]
      at Trycatch/trycatch()[flex\Trycatch.mxml:21]
      at Trycatch/testUpdate()[flex\Trycatch.mxml:43]
      at Trycatch/___Application1_creationComplete()[flex\Trycatch.mxml:3]
      at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.core::UIComponent/set initialized()[C:\dev\GMC\sdk\frameworks\mx\core\UIComponent.as:1161]
      at mx.managers::LayoutManager/mx.managers:LayoutManager::doPhasedInstantiation()[C:\dev\GMC\ sdk\frameworks\mx\managers\LayoutManager.as:687]
      at Function/ http://adobe.com/AS3/2006/builtin::apply()
      at mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher2()[C:\dev\GMC\sdk\framework s\mx\core\UIComponent.as:7789]
      at mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher()[C:\dev\GMC\sdk\frameworks \mx\core\UIComponent.as:7732]

      Any thoughts?

      --
      Jürgen Failenschmid