-
Notifications
You must be signed in to change notification settings - Fork 14
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
Throwing own exception in method causes "InvocationTargetRuntimeException" #32
Comments
Interesting. The reason this is happening is due to the methods being I think though, having JewelCli propagate the original exception instead On Wed, Jul 9, 2014 at 7:54 PM, Simon Herter [email protected]
|
I currently use the workaround you describe.
|
Its not closed source, its a copy of the classes from here, which are I think perhaps though, it would prefer to unwrap and re-throw the On Thu, Jul 10, 2014 at 12:31 AM, Simon Herter [email protected]
|
There is, though, the question of what to do about the order the methods On Thu, Jul 10, 2014 at 8:00 AM, Tim Wood [email protected] wrote:
|
I don't think collecting all exceptions and then throw ArgumentValidationException instead is how exceptions in general should work. The client also looses the flexibility to throw and cache other exceptions. As a programmer, I would expect to receive the exact exception I have thrown in a setter method as soon as the error occurs, no matter in which order the setter methods are called. However, I understand your point if you wan't to print all errors at once rather than let the user try again and again. What I'm not sure about is if only runtime exceptions should be allowed or checked exceptions as well. Allowing checked exceptions would maybe pollute the client code a bit, but it is easily possible that you want to have some file system checks, for example, for an option that represents a file. |
I don't see how this can help to clean up the stack trace of the original exception, since the setter method will always be called by reflect.Method.invoke. |
Alternate solution to lexicalscope#32
I just stumbled across this and handling them as an ArgumentValidationException worked well enough for me. Returns useful error text such as: Unexpected error (Date 1/1/20155 is out of bounds): --begin-date -b value : Begin Date. (M/d/yyyy) |
When I throw an exception in a method that gets invoked by
CliFactory.parseArgumentsUsingInstance()
I get aInvocationTargetRuntimeException
in the first place rather than my own exception.I don't know if there are reasons against it, but I would expect to receive my own exception. That way I could do some argument validation in the methods and throw exceptions respectively.
The text was updated successfully, but these errors were encountered: