+ 2
Exceptions
Can anyone explain to me what exceptions are? I really don't get it.
4 Respostas
+ 2
See also this code by LukArToDo:
https://code.sololearn.com/cE5BpKwo33DN/?ref=app
+ 1
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.
0
Exceptions are just errors in your code