Exceptions | SoloLearn: Learn to code for FREE!



Can anyone explain to me what exceptions are? I really don't get it.

6/30/2019 4:45:37 PM

Pasqalle Soeters

3 Answers

New Answer


https://www.sololearn.com/learn/Java/2175/?ref=app https://www.sololearn.com/learn/Java/2176/?ref=app


See also this code by LukArToDo: https://code.sololearn.com/cE5BpKwo33DN/?ref=app


Exceptions are errors/problems: Some examples: String str = null; System.out.println(str.length()); -> an empty String has no length() int x = 3; int y = 0; System.out.println(x/y); -> dividing by zero Having a Scanner scan: int x = scan.nextInt(); If you don't enter an integer you will get an error message. If you want to open a file which does not exist... With exception handling you can catch this exceptions and decide what to do. Your program will not just crash.