Reputation: 635
Loading a file in flex prompt for error called Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type. What i need to do is when this error occurs i want to call a function. So i put the block of code causing an error occurrence in try catch block. But when error occurred it does not come in catch. Below is snippet of code.
try {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
loader.loadBytes(fileReferance.data);
}
catch(err:*) {
functionTocall(fileReferance);
}
How to handle it..
Upvotes: 1
Views: 679
Reputation: 18820
just add another listener which is listening for the IOErrorEvent
:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderErrorHandler);
loader.loadBytes(fileReferance.data);
that's it
Upvotes: 0
Reputation: 7294
There are 2 types of errors in flash: synchronous and asynchronous. Synchronous errors can be handled with try..catch
block. Such errors are thrown immediately, when code execution fails. But you can't know exactly, when asynchronous error will be thrown. You're trying to handle asynchronous error. That's why you cannot catch it the way you do it.
You should add event listener for IOErrorEvent.
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
...
private function onIOError(e:IOErrorEvent) {
....
}
Upvotes: 6