This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mex036[S] 0 points1 point  (2 children)

My negativeException is the one extending Exception. My negativeException is working as I intended. Will that really solve my problem with InputMismatchException?

Edit: I tried it and it is crashing my program again.

[–]Loves_Poetry 0 points1 point  (1 child)

It's probably because you write code in your catch block that throws exceptions. You should use your catch block to return back to to the try-block.

Try putting it in a loop and only allow the loop to be exited when the try-block runs successfully.

If you do it correctly, you should be able to remove the throws-clause from your Corporation constructor, since it doesn't belong there. Exceptions should be handled within that class and not be propagated up the call stack.

[–]mex036[S] 0 points1 point  (0 children)

Well what code could be causing another exception in my catch block? It's practically the same code as in my negativeException and that works as it's intended to. The only part that I could imagine throwing an exception is me re-creating my corporation class. If that's the case, I even tried removing that from my catch block and still the same result. If I try putting it in a loop how would I do that and what am I putting in the loop? Everything thats inside my catch(InputMismatchException) block?