I have followed the tutorial for building a Java Service installer and have managed to build an installer for our application. The documentation is very clear and this is exactly what we need.
There was one question I couldn't find an answer to: how should my Java application handle errors during start or stopping? Should I throw an exception or call System.exit()? Or is there some other way to signal that the service cannot start?
While I was working on my installer, I ran into a few bugs on my side that led to an exception being thrown from main(), and then from stop().
The exception from main() seems to have been ignored, and the service reported starting.
The exception from stop() led to the service hanging, and could only be stopped by terminating the process.
While stopping, I will just be sure to catch and log all exceptions and return.
But how can I signal from Java that I have encountered a fatal error and cannot start the service?