테스트 화면


//메소드 예외처리


import java.util.Scanner;

import java.util.InputMismatchException;

class ExceptionTest3 

{

int a, b, c;

//메소드 예외처리

public ExceptionTest3() throws InputMismatchException, ArithmeticException{

start();

}

public void start() throws InputMismatchException, ArithmeticException{

output();

}

public void output() throws InputMismatchException, ArithmeticException{

input();

c = a / b;

System.out.println("c = "+c);

}

public void input() throws InputMismatchException{

Scanner scan = new Scanner(System.in);

System.out.print("a = ");

a = scan.nextInt();

System.out.print("b = ");

b = scan.nextInt();

}

}

=====================================================================

메인 화면

import java.util.InputMismatchException;

public class ExceptionTest3Main 

{

public static void main(String[] args)

{

try{

ExceptionTest3 et3 = new ExceptionTest3();

}catch(Exception e){

System.out.println("예외 발생");

}

}

}



Posted by Hyun CHO
,