Changes

Jump to navigation Jump to search
590 bytes added ,  18:46, 3 April 2015
Line 403: Line 403:  
// add throws to main declaration...  
 
// add throws to main declaration...  
 
}
 
}
 +
}</source>
 +
=== Runtime exceptions ===
 +
The compiler does not force you to handle them.
 +
<source lang="java">
 +
package tutorialJava;
 +
 +
public class RuntimeExceptions {
 +
 +
public static void main(String[] args) {
 +
int value = 7;
 +
String[] texts = {"cero", "one", "two"};
 +
 +
//runtime exceptions
 +
//// division by 0(ArithmeticException)
 +
try {
 +
value = value/0;
 +
} catch (Exception e){
 +
System.out.println(e.getMessage());
 +
System.out.println(e.toString());
 +
e.printStackTrace();
 +
}
 +
//// ArrayIndexOutOfBoundsException
 +
System.out.println(texts[3]);
 +
// NoPointerException
 +
 +
}
 +
 
}</source>
 
}</source>
  

Navigation menu