View Full Version : try, catch, finally statements
costa
June 27th, 2007, 02:07 AM
Dear all,
I read senocular article about the use of try, catch and finally statements and finally I understood their use (thanks senocular). However, I doubt came out, If a have a preloader using those statements in the COMPLETE event function (Event.COMPLETE), it is not necessary to have a specific function for handle errors (for example IOErrorEvent.IO_ERROR)? Or the idea behind to have a specific function for handle errors is, it will capture all the errors and “catch” statement only those I declare?
I hope, I explained myself well.
Thanks
dthought
June 27th, 2007, 02:17 AM
Generally, you only need to catch errors that you want to process in some way. You don't need to catch things just because they're there to be caught.
costa
June 27th, 2007, 02:25 AM
Generally, you only need to catch errors that you want to process in some way. You don't need to catch things just because they're there to be caught.
So the answer is i can use the statements or the function?
Thanks
Dazzer
June 27th, 2007, 08:54 AM
Well most errors you would like to catch. Because if an error isn't caught, it will bubble up to the player. And if it hits the player, the player stops.
In java this is especially important. But less so in flash.
The main reason why you would catch it is to allow the flash player to continue operation (save it from dying).
Krilnon
June 27th, 2007, 09:12 AM
There is a difference between Flash Player errors and 'error' events. You mentioned IOErrorEvent; that isn't something that you could catch with a catch statement. You would need to 'catch' that error (but it's really an event) by setting up an event listener for it and defining the handler so that it would provide whatever error-handling behavior that you want your application to have.
costa
June 27th, 2007, 03:38 PM
Thanks for replies. I am starting to understand the difference.
Thanks
senocular
June 27th, 2007, 04:13 PM
check the tips thread. There is mention of both kinds of events and the use of try/catch and handling async errors
Also Dazzer is right about catching errors. If its possible an error can be thrown, its usually a good idea to put it in a try/catch block because if and when it happens, it will prevent the execution of the remaining script in the block unless caught (even if you don't do anything in the catch)
And if you want to see alerts with uncaught exceptions (errors) in your browser, install the debugger plugin. These versions of the plugin are available in the players (or respectively named) folder within your Flash/Flex installation.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.