Frage

Flash is throwing an uncatchable exception when using a URLLoader with no internet connection:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error

Since I'm developing a phone app, there's always a chance the internet will drop. I want to detect this and show an error dialog. Is there anyway to catch and suppress this error? Code follows:

try
{
var request:URLRequest = new URLRequest(API_URL + "/" + API_VERSION + "/" + gameKey + "/" + type);

request.data = jsonString;
request.method = URLRequestMethod.POST;
request.requestHeaders.push(new URLRequestHeader("Authorization", MD5.hash(jsonString + secretKey)));

var loader:URLLoader = new URLLoader();
loader.data = type;
loader.addEventListener(Event.COMPLETE, onRequestComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onRequestError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onRequestSecurityError);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onRequestStatus);

loader.load(request);
} catch (Error) { trace("URLLoader Failed");}

The exception stack claims the it is raised on the line where the URLLoader is allocated, but while debugging execution runs past that line, and the exception comes from an unknown place. The catch block is never invoked. The error event handlers are hit, but only AFTER the exception is shown as being un-handled by the Flash Player.

Any help would be appreciated. I'm tearing my hair out and can't find the answer online (other people have reported the same problem but there are no solutions.)

War es hilfreich?

Lösung

Flash is throwing an uncatchable exception when using a URLLoader with no internet connection

To catch them, go with uncaughtErrorEvents in LoaderInfo. For example you could subscribe for the uncaught errors and manage them with some fallback logic:

//Somewhere, you could manage it globally, or declare before risky part
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);


private function onUncaughtError(e:UncaughtErrorEvent):void {
    e.preventDefault();
    trace("Scorpion: come here! - " + e.toString());
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top