URLConnection.Error Doesn't Fire for Error -1009 Connection Offline

I expect the URLConnection’s Error event to fire on any error so I can handle it there, but instead the code throws a NetworkException exception. Is this a bug?

dim Downloader as new URLConnection
AddHandler Downloader.error, AddressOf DownloadError
Downloader.SendSync("GET",URL, DownLoadFile,15)

Breakpoint in method DownloadError never fires:

Use downloader.send

To follow up with some more info, the docs aren’t really clear but it seems like the events aren’t raised if you are using SendSync. Switching to asynchronous request (Send) will raise events.

I would especially recommend this for a Check for Updates function, otherwise your whole app freezes while it awaits a response. You can subclass URLConnection and use the ContentsReceived event to parse the response and alert the user.

1 Like

Normal behaviour i’d say.

Handle it at the end of your method:

 Exception e As Networkexception
 // do something with e here:

I know how to Try-Catch, but what’s the point of the Error event then?

Async is event based if you use the sync stuff why you expect an event to happen then? The your better off using the events anyway?

Yes, I learned that just now, thanks to @Tim_Parnell :slight_smile:

Because the documentation doesn’t say anything about the event not happening in Sync mode.

It actually does, here where it’s expected:


You are clearly using the SendSync ?