Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. package dudasForo;
  2.  
  3. public class Ejemplo_RuntimeException {
  4.  
  5.     private void exceptionGenerator() throws RuntimeException {
  6.         while (true) {
  7.             if ((int) (Math.random() * 100) < 90) {
  8.                 System.out.println("Tarea X correcta");
  9.             } else {
  10.                 throw new RuntimeException("Tarea X con error");
  11.             }
  12.         }
  13.     }
  14.  
  15.     private void exec() {
  16.         try {
  17.             exceptionGenerator();
  18.         } catch (Exception e) {
  19.             System.out.println(e.getMessage());
  20.         }
  21.     }
  22.  
  23.     public static void main(String[] args) {
  24.         new Ejercicio19_JavierAlbaranez().exec();
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement