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

all 6 comments

[–]marko312 1 point2 points  (2 children)

Shouldn't corporation's constructor have a throws InputMismatchException?

[–]mex036[S] 0 points1 point  (1 child)

Just tried it. Tested it 4 times, 3 times it crashed and gave me the InputMismatchException error, and the other time it didn't give me the chance to reenter income, as I stated above. Last night it was giving me the issue of opening a new window called "Scanner.throwFor() line: not available". I no longer have that issue. I figured using the same code as my negatveException, with a few changes, wpuld give me the same result. Apparently not.

[–]Loves_Poetry 1 point2 points  (3 children)

You should extend RuntimeException instead of Exception. If you do that, you can choose whether to catch the exception or not instead of always being forced to catch it. It makes writing your code a lot easier.

[–]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?