forked from mouredev/hello-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThrowExample.java
More file actions
25 lines (21 loc) · 693 Bytes
/
Copy pathThrowExample.java
File metadata and controls
25 lines (21 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package basic.c09_exceptions;
/*
Clase 70 - Lanzamiento de excepciones
Vídeo: https://youtu.be/JOAqpdM36wI?t=28611
*/
public class ThrowExample {
public void checkAge(int age) throws IllegalArgumentException {
if (age < 18) {
throw new IllegalArgumentException("Tienes que ser mayor de edad");
} else {
System.out.println("Es mayor de edad");
}
}
public void checkScore(int score) throws CustomException {
if (score < 0 || score > 100) {
throw new CustomException("La puntuación debe estar entre 0 y 100");
} else {
System.out.println("Puntuación válida: " + score);
}
}
}