2 Star 0 Fork 0

热门极速下载/hello-java

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Exceptions.java 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
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");
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_trending/hello-java.git
git@gitee.com:mirrors_trending/hello-java.git
mirrors_trending
hello-java
hello-java
main

搜索帮助