Advertisement
Felanpro

Exception handling

Aug 30th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class program1
  4. {
  5.     public static void main(String args[])
  6.     {
  7.         Scanner scan = new Scanner(System.in);
  8.        
  9.         //If there's an error in the try{} block do catch{} block.
  10.         //Instead of raising a weird error we simply just raise catch().
  11.         try{
  12.             System.out.print("Type in first number: ");
  13.             scan.nextInt();
  14.         }
  15.         catch(Exception e)
  16.         {
  17.             System.out.print("Unable to complete.");
  18.         }
  19.        
  20.         /*
  21.          * In this case the user types a string
  22.          * in to the input that scans the input.
  23.          * That will raise an error. But instead of giving that
  24.          * specific error we simply just execute the catch block.
  25.          */
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement