DESARROLLO DE APLICACIONES CON MANEJO DE ARCHIVOS DE TEXTO Y EL MANEJO DE EXCEPCIONES EN JAVA
jesusmatizEnsayo1 de Mayo de 2017
1.310 Palabras (6 Páginas)229 Visitas
Actividad 1
Alumno:
Jesús María Matiz Salazar
Curso:
DESARROLLO DE APLICACIONES CON MANEJO DE ARCHIVOS DE TEXTO Y EL MANEJO DE EXCEPCIONES EN JAVA
Excepciones Java
- ArrayIndexOutOfBoundsException
- ArrayStoreException
- ClassCastException
- CloneNotSupportedException
- EnumConstantNotPresentException
- IndexOutOfBoundsException
- NegativeArraySizeException
Instructor:
GUSTAVO ADOLFO MURILLO PARAMO
// PRIMER EJEMPLO DE TRY CATCH
// Esta excepción se presenta cuando se busca fuera del índice del array
int[] valores = new int[3];
valores[2] = 3;
try{
System.out.println(valores[3]);
}catch(ArrayIndexOutOfBoundsException ex){
System.out.println("Error 1 -> " + ex.toString());
}
// SEGUNDO EJEMPLO DE TRY CATCH
// Esta excepción se presenta cuando se trata de cambiar un objeto de un tipo a otro
Object x[] = new String[3];
try{
x[0] = new Integer(0);
}catch(ArrayStoreException ex){
System.out.println("Error 2 -> " + ex.toString());
}
// TERCER EJEMPLO DE TRY CATCH
// Esta excepion se presenta cuando se pretende castear un objeto de un tipo a otro
try{
Object x2 = new Integer(0);
System.out.println((String)x2);
}catch(ClassCastException ex){
System.out.println("Error 3 -> " + ex.toString());
}
// CUARTO EJEMPLO DE TRY CATCH
// Esta excepción se presenta cuando se pretende hacer un clon de un objeto padre sin // que este implemente la interface Cloneable
public Object clone(){
Object obj=null;
try{
obj=super.clone();
}catch(CloneNotSupportedException ex){
System.out.println("Error 4 -> " + ex.toString());
}
return obj;
}
// QUINTO EJEMPLO DE TRY CATCH
// Esta excepción se lanza cuando se pretende llamar a un enum que no se encuentra en la lista
try
{
Demarcacion delantero = Demarcacion.DELANTERO;
}
...