+ 4

Try catch throw definition java help

did i understand them correctly,correct me if im wrong (try)-write the code within the type that you think an exception might occur. (catch)-receive the exception from try and do the neccessary steps given to it like " catch(Exception e){System.out.println("you did it wrong");". (throw)-coder will write the specific exception error inside the throw.if that exception really happens,it will show the exception error that the coder has written in the output.so we decide how the error will look like

3rd Nov 2017, 6:53 PM
oyl
2 Answers
0
The try and catch portions are correct, the throw I am not entirely sure on as i have only used Try {}Catch {} in my code.
3rd Nov 2017, 7:28 PM
Adrian Johnson
Adrian Johnson - avatar
0
throw will throw the exception you put there yes. It behaves like a usual exception. So unless you catch it, it will crash your program. That's why it is discouraged.
3rd Nov 2017, 9:31 PM
1of3
1of3 - avatar