AndroidAsync icon indicating copy to clipboard operation
AndroidAsync copied to clipboard

Unable to specifically catch server startup failures

Open io7m opened this issue 10 years ago • 1 comments

Hello.

Currently, the listen() method runs asynchronously and if any errors are raised, they're dumped into whatever is the current uncaught exception handler. Unless I'm mistaken, there doesn't seem to be a simple and reliable way to catch "the server failed to start up" errors. I can install an uncaught exception handler, but that'll catch every possible type of exception and I won't be able to tell which of those came from the server.

Case in point:

AsyncHttpServer s = new AsyncHttpServer();
s.listen(99999);  // Will obviously fail

The server will throw an IllegalArgumentException when executed in a Runnable in the background somewhere, which will be treated as an uncaught exception by the Android runtime and the entire program will crash.

What I would really like is to be able to supply a simple callback such as:

interface StartupListener
{
  void onServerStartupSucceeded(AsyncHttpServer s);
  void onServerStartupFailed(Throwable x);
}

... so that I can reliably detect failed startups and notify the user of exactly what went wrong.

Would you accept patches that implemented this? It doesn't seem like it'd be difficult to add.

io7m avatar Apr 14 '15 15:04 io7m

I find listen() returns null, then client can't connect to my server until I restart the whole process.

rancpine avatar May 09 '21 09:05 rancpine