import java.util.Scanner; public class TryScanner { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try{ System.out.println("input int:"); Scanner scanner=new Scanner(System.in); int i=scanner.nextInt(); System.out.printf("%d ",i); }catch(java.util.InputMismatchException e) { System.out.println(e.toString()); System.out.println(e.getMessage()); } System.out.println("exit..."); } }
input int: qq java.util.InputMismatchException null exit...
public class ErrorExceptionDemo { /** * @param args */ public static void main(String[] args) { int i=2; try{ for(int j=-1;i<3;j++) { int k=i/j; System.out.printf("%d ",k); } }catch(java.lang.ArithmeticException e) { System.out.printf("%s ",e.getMessage()); System.out.printf("%s ",e.toString()); } } }