Reputation: 523
So this is not an error but rather a thought, I have a java class, Jform1, which is a JForm. I am trying to take only double values in to the 3 textfields and then do some computation with these numbers. But if the user fails to enter the double values and enters any characters I want to throw an exception, not just display that the it is a char and not valid either in a label or a dialogbox. So I want to create a *entered_Valuenotvalid* exception class how do I do that? I can't even think of how to do that, mainly because this is a seprate class itself and then the Jform is a seprate class so if error happens here then i have to get the exception from the *entered_Valuenotvalid* class.
the only thing I can think of is extending the *entered_Valuenotvalid* class, or is there a better way to do that.
Upvotes: 0
Views: 150
Reputation: 47759
An exception is just a subclass of Throwable. Create the class you want, choose which JDK exception to subclass (probably IllegalArgumentException), create an instance, and throw
it.
Upvotes: 1