Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom exception handling for Runnable/Callable #541

Closed
remkop opened this issue Nov 9, 2018 · 4 comments
Closed

Custom exception handling for Runnable/Callable #541

remkop opened this issue Nov 9, 2018 · 4 comments

Comments

@remkop
Copy link
Owner

remkop commented Nov 9, 2018

The current convenience API doesn’t make it easy to have different exit codes for different exceptions. The most convenient API is to invoke CommandLine.run(new MyRunnable(), args) in the main method, but this doesn’t let you specify an exit code. The parseWithHandlers method gives more control but is more clunky and doesn’t allow different exit codes for different exceptions.

One idea is to let the Runnable/Callable handle the exception if it implements the IExceptionHandler2 interface.

This interface could potentially be split into two super interfaces IParameterExceptionHandler and IExecutionExceptionHandler to allow applications to handle only some exceptions and use the default exception handler for the rest.

Related: #424

@bobtiernay-okta
Copy link
Contributor

Another option might be to allow annotating the exception. This is what Spring does for MVC error codes

@remkop
Copy link
Owner Author

remkop commented Nov 19, 2018

Can you provide a link?

@remkop
Copy link
Owner Author

remkop commented Nov 19, 2018

Interesting idea, thank you!

@remkop remkop modified the milestones: 4.0, 4.0-alpha-3 Apr 24, 2019
remkop added a commit that referenced this issue Apr 24, 2019
…te` and `tryExecute` methods: configurable convenience methods with improved exit code support.

* The new `execute` and `tryExecute` methods are similar to the `run`, `call` and `invoke` methods, but are not static, so they allow parser configuration.
* In addition, these methods, in combination with the new `IExitCodeGenerator` and `IExitCodeExceptionMapper` interfaces, offer clean exit code support.
* Finally, the `tryExecute` method rethrows any exception thrown from the Runnable, Callable or Method, while `execute` is guaranteed to never throw an exception.
* Many variants of the previous `run`, `call` and `invoke` convenience methods are now deprecated in favor of the new `execute` methods.
* Many methods on `AbstractHandler` are now deprecated.

Still TODO: tests and documentation.
remkop added a commit that referenced this issue Apr 26, 2019
remkop added a commit that referenced this issue Apr 26, 2019
remkop added a commit that referenced this issue Apr 27, 2019
remkop added a commit that referenced this issue Apr 30, 2019
remkop added a commit that referenced this issue May 1, 2019
…invoke() methods and associated classes and interfaces; update Javadoc
@remkop remkop closed this as completed in 1161b05 May 2, 2019
remkop added a commit that referenced this issue May 3, 2019
…er interface to simplify custom implementations; unwrap the `ExecutionException` in the `CommandLine.execute` method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants