Created
April 25, 2017 22:22
-
-
Save antoc0d3/5888a8c3e0f79790babb68d57d13fea2 to your computer and use it in GitHub Desktop.
Excepciones en JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
//Division entre cero | |
try { | |
int x = 5 / 0; | |
} catch (ArithmeticException e) { | |
System.out.println(e); | |
} | |
//Fuera del tamaño del arreglo | |
try { | |
int [] y = new int[10]; | |
y[100]= 15; | |
} catch (ArrayIndexOutOfBoundsException e) { | |
System.out.println(e); | |
} | |
//Fuera del tamaño del String | |
try { | |
String cad ="java"; | |
cad.charAt(50); | |
} catch (StringIndexOutOfBoundsException e) { | |
System.out.println(e); | |
} | |
//Error de puntero null | |
try { | |
JButton x = null; | |
x.setBounds(0,0,100,15); | |
} catch (NullPointerException e) { | |
System.out.println(e); | |
} | |
//Error de formato | |
try { | |
Integer o = Integer.parseInt("jaja"); | |
} catch (NumberFormatException e) { | |
System.out.println(e); | |
} | |
//Error de casteo | |
try { | |
//Polimorfismo | |
Object obj = new JButton(); | |
Integer a = (Integer)obj; | |
} catch (ClassCastException e) { | |
System.out.println(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment