代码拉取完成,页面将自动刷新
package basic.c09_exceptions;
/*
Clase 8 - Manejo de excepciones, depuración y extras (28/05/2025)
Vídeo: https://www.twitch.tv/videos/2471305243
*/
public class Exceptions {
public static void main(String[] args) {
// Manejo de excepciones
// try catch
try {
var result = 10 / 0;
System.out.println(result);
} catch (ArithmeticException e) {
System.out.println("Error: " + e);
}
// try con múltiples catch
try {
var result = 10 / 5;
System.out.println(result);
var name = "Brais";
name = null;
System.out.println("Name: " + name.toUpperCase());
} catch (ArithmeticException e) {
System.out.println("Cuidado con dividir algo que no puedes: " + e);
} catch (NullPointerException e) {
System.out.println("Ha ocurrido un null pointer mítico!");
} catch (Exception e) {
System.out.println("Se ha producido un error no esperado");
}
// finally
try {
var result = 10 / 0;
System.out.println(result);
} catch (ArithmeticException e) {
System.out.println("Error: " + e);
} finally {
System.out.println("Fin del bloque try-catch");
}
// throw
var throwExample = new ThrowExample();
try {
throwExample.checkAge(15);
} catch (IllegalArgumentException e) {
System.out.println("Error revisando la edad: " + e.getMessage());
}
// Excepción personalizada
try {
throwExample.checkScore(450);
} catch (CustomException e) {
System.out.println("Error revisando la puntuación: "+ e.getMessage());
}
System.out.println("Fin");
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。