Comando throw: qué hace y cómo se usa
¿Qué hace el comando throw?
throw new IllegalArgumentException("Edad negativa");: lanzar una IllegalArgumentException con el mensaje «Edad negativa».
Ejemplos de throw
$ throw new IllegalArgumentException("Edad negativa");throw new IllegalArgumentException("Edad negativa");: lanzar una IllegalArgumentException con el mensaje «Edad negativa».
$ throw "No existe el archivo"throw detiene la ejecución.
$ throw "Falta"El script se detiene (o salta al catch).
Pruébalo tú
Para lanzar una IllegalArgumentException con el mensaje «Edad negativa» se escribe esta línea.
Aprende más en Tecleo
En Tecleo no lees: escribes los comandos y te corregimos al momento, con explicaciones y repaso para que no se te olviden.
Practica con «Java: programación orientada a objetos» Practica con «PowerShell desde cero»