1 Reply Latest reply on Sep 26, 2007 3:54 PM by Senor_Roberto

    try catch not working at all???

      Ok. So ultimately, I want to catch an exception when calling StyleManager.loadStyleDeclarations("bogus.swf") I attempt to wrap this loadStyleDeclarations in a try/catch but the catch never executes and I ALWAYS get Flex's default runtime error dialog complaining that "bogus.swf" cannot be found. I tried to catch Error....and IOError but nothing. I can't seem to catch this error. So....I tried catching a simple error when loading a url and that does not seem to work. Here is the example right from the Flex API doc and it does not work - it does not catch the IOError - I get the default error dialog from Flex.

      public function go():void {
      var loader:URLLoader = new URLLoader();

      var request:URLRequest = new URLRequest("urlLoaderExample.txt");
      try {
      } catch (error:Error) {
      trace("Unable to load requested document.");

      WHAT IS GOING ON HERE? How can I catch these exceptions? This is so frustrating....spending hours on this simple little task. I need to verify the URL/SWF OR just catch the exception, but I cant do either.

      Thanks for any help!!!
        • 1. Re: try catch not working at all???
          Senor_Roberto Level 1
          I think you'll find that some of the API uses events to register errors as opposed to exceptions. So in your URLRequest example, you need to bind a listener to IOErrorEvent.IO_ERROR to handle an IOError, instead of trying to catch one - the IOError is not an exception, it's an error event.

          You need to look at the API to see if exceptions are being thrown or if error events are being dispatched.

          I don't know Adobe's philosophy on error exceptions vs error events, but from looking at the documentation it seems that error exceptions are a feature of ActionScript 3 and error events are an artifact of the Flex/Flash API.

          Maybe for consistency of event handling, maybe for legacy code reasons?