Closed timboudreau closed 2 years ago
So an exception is being thrown by a field initializer of your application?
The run() method for application handles failures, but construction and execution of an Application is two-phase right now, like:
public static void main(String[] arguments)
{
new MyApplication().run(arguments);
}
The only way I can think of to really make sure the main() method captures the failure is to have construction and running of the application performed by KivaKit, like:
public static void main(String[] arguments)
{
Application.run(MyApplication.class);
}
I'm not able to build right now, so I'm not positive that these changes work, but the idea is that this method
public static <T extends Application> Result<ApplicationExit> run(Listener listener,
Class<T> applicationType,
String[] arguments)
can be used to create the application and run it in one shot. This way construction and execution are scoped properly, and all exceptions are caught within the method. The Result object contains an ApplicationExit value and any messages that were caught. The ApplicationExit object contains any exception and an enum ExitCode (either success or failure as of now).
PR is here: https://github.com/Telenav/kivakit/pull/119
Failure should probably throw an exception if nothing handles or is listening to the failure. Or return a FailureResult that lets the application decide to do that.