[Flashcoders] what happens to exceptions i throw in async functions.
Hi All some code to look at first function meth2() { var x:XML = new XML(); try{ x.onLoad = function(success)//Delegate.create(this,handleXmlLoad); { throw new CustomError(); } x.load(somefile.xml); } catch(e:CustomError) { trace(caught in child); } } function handleXmlLoad(success:Boolean) { throw new CustomError(); } i am not able to catch this error in either the anon function or the function delegate. has anybody have any idea of how to handle asynchranous exception handeling in flash? thanks j -- j:pn ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] what happens to exceptions i throw in async functions.
i am not able to catch this error in either the anon function or the function delegate. has anybody have any idea of how to handle asynchranous exception handeling in flash? I don't think you can do what you're planning, there; it appears that XML.load() starts a new execution thread, which ignores the try/catch block in which it was invoked. Your best bet for error handling is to analyze the XML in your onLoad handler. If you detect an error condition, let the handler deal with it. This does mean that instead of generating an exception and catching it, you have to do some logic to check for errors, but it seems to be Flash's way. Since Flash is designed for the internet, functions which instigate a new HTTP request are always going to run asynchronously -- since there's just no telling when the heck they'll complete. It's a compromise. Personally, I'd love to have the option of a synchronous XML.load() method, since often I'm just reading from files in the same directory as the SWF. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] what happens to exceptions i throw in async functions.
well currently i am handeling my errors by dispatching them (take the same error object add a type property). this seems terribly inelegeant, since I use throw all over the place except in one of the places i need it most. since that exception is being traced out i would however imagine that it does somewhere. where is this and can i change the behaviour there to lend more consistency my code? On 1/5/06, Alan MacDougall [EMAIL PROTECTED] wrote: i am not able to catch this error in either the anon function or the function delegate. has anybody have any idea of how to handle asynchranous exception handeling in flash? I don't think you can do what you're planning, there; it appears that XML.load() starts a new execution thread, which ignores the try/catch block in which it was invoked. Your best bet for error handling is to analyze the XML in your onLoad handler. If you detect an error condition, let the handler deal with it. This does mean that instead of generating an exception and catching it, you have to do some logic to check for errors, but it seems to be Flash's way. Since Flash is designed for the internet, functions which instigate a new HTTP request are always going to run asynchronously -- since there's just no telling when the heck they'll complete. It's a compromise. Personally, I'd love to have the option of a synchronous XML.load() method, since often I'm just reading from files in the same directory as the SWF. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- j:pn ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] what happens to exceptions i throw in async functions.
On Jan 5, 2006, at 4:26 PM, Johannes Nel wrote: has anybody have any idea of how to handle asynchranous exception handeling in flash? You need to do something more like this: function handleXmlLoad(success:Boolean) { if (success) { trace(Load successful.); } else { trace(Load NOT successful.); //var error = new CustomError(); } } function meth2() { var x:XML = new XML(); // x.ignoreWhite = true; x.onLoad = mx.utils.Delegate.create(this, handleXmlLoad); x.load(somefile.xml); } meth2(); blue skies, bryan ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] what happens to exceptions i throw in async functions.
no mate you are missing what i am trying to acheive. On 1/5/06, bryan.rice [EMAIL PROTECTED] wrote: On Jan 5, 2006, at 4:26 PM, Johannes Nel wrote: has anybody have any idea of how to handle asynchranous exception handeling in flash? You need to do something more like this: function handleXmlLoad(success:Boolean) { if (success) { trace(Load successful.); } else { trace(Load NOT successful.); //var error = new CustomError(); } } function meth2() { var x:XML = new XML(); // x.ignoreWhite = true; x.onLoad = mx.utils.Delegate.create(this, handleXmlLoad); x.load(somefile.xml); } meth2(); blue skies, bryan ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- j:pn ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] what happens to exceptions i throw in async functions.
On Jan 5, 2006, at 6:26 PM, Johannes Nel wrote: no mate you are missing what i am trying to acheive. Sorry - misread your email. I don't think you can do it. Try...Catch and Xml.onLoad are like oil and water as far as I can tell. You will have to wait to load your xml before you start your try...catch block I think. blue skies, bryan ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders