0

I'm working on some flash app. Now, to test customer side of it I can use Flash Player debugger version that will save logs and show error messages. When it's deployed on the customer side - they will have a regular Flash Player version which means I will have no access to error messages if errors will happen. So I would like to equip it with some tool that would capture all of my trace messages in code and errors text. As for trace messages that's fairly simple, I just override the function in my code so it sends a POST request with trace message to a logger server, but how can I get a hold of the error message? Is there a known approach to this or some trick that somebody can suggest?

2 Answers 2

1

You can install the debug version of flash as your browser's default (in Chrome, you must disable the built-in player), so if you wanted to test user experience and debug, this would be the ideal solution.

However, to answer your question: there's no method for universally catching all errors, and redirecting them (that I know of). You'd have to encapsulate problem code ahead of time with try...catch statements, and send the property back on catch. For example:

try {
    this["foo"]();
} catch (e:Error) {
    trace(e);
}

In the debug version, the traced value would be TypeError: Error #1006: value is not a function. And while the standard version will only output TypeError: Error #1006, (a notably less descriptive error), what we're missing is any reference to where the error occured. To get this, we need to use Error.getStackTrace() to see the call stack and the line where the error occurred. In debug, this outputs the following:

TypeError: Error #1006: value is not a function.
    at Shell_fla::MainTimeline/init()[C:\Projects\shell.as:91

In the standard client, we get a dissapointing null. In short, you cannot get any valuable info from the client versions.

The best advice I can give is to write around your problem code with your own custom error reports. For example, catch IO errors and trace the file it failed to load, or if you're expecting an object.foo, first try if (object.hasOwnProperty("foo")) { // do something } else { trace("foo not found in " + object.name) }. Code defensively.

Cheers,

2
  • Thank you for a comprehensive explanation, Atriace! I'll wait if anyone else will have anything to add to this and mark your reply as an answer later on.
    – waterplea
    Oct 18, 2013 at 8:40
  • I've checked the link on getStackTrace() - looks like it should work in non-debug environment starting Flash Player 11.4/AIR 3.4. Gotta try that.
    – waterplea
    Oct 22, 2013 at 13:44
1

I've discovered this post on StackOverflow: How to catch all exceptions in Flex?

It answers my question, strange that I haven't ran into it while I was googling prior to asking.

3
  • Oooo, shiny! I'm going to have to try that out myself. Nice find. :)
    – Atriace
    Nov 8, 2013 at 13:52
  • Yeah, that works great for my Flash Player projects, but I have problems with AIR one. I am restricted to Flex SDK 4.6 which uses AIR 3.1 namespace. Therefore the highest swf-version I can compile AIR with is 14, but I need 18 to have getStackTrace() not show null. So although my application is ran in AIR 3.9 runtime, it still returns null :( Is there a way to target higher versions than my SDK has?
    – waterplea
    Nov 9, 2013 at 7:29
  • JEEZ, now that's just plain ridiculous! alivelearn.net/?p=623 Turns out I can easily run my AIR app in debug mode even on the release version of AIR runtime without debug launchers and all other stuff. Just placing empty file named 'debug' into ApplicationDirectory/META-INF/AIR does all the magic I need. Crap, how come that is not documented/poping up for every "air debug" google search? Could have saved me a sh**load of time! If you are working with AIR apps, Atriace, that could be helpful to you too, check it out :)
    – waterplea
    Nov 9, 2013 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.