Changes
Jump to navigation
Jump to search
← Older edit
Newer edit →
Java
(view source)
Revision as of 18:46, 3 April 2015
590 bytes added
,
18:46, 3 April 2015
→Exceptions
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>
Rafahsolis
Bureaucrats
,
Administrators
2,306
edits
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
Variants
Views
Read
View source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
Special pages
Printable version