달력

62025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30


// Error가생기는 Exception

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class  ExceptionEx2
{

 public static void main( String[] args ) /* throws IOException */      // throw가 있고 throws가 있다.
 {
  BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) ) ;

  int a = 0;    // a를 빼낸다.

  try
  {
   System.out.print( "정수 : " );
   a = Integer.parseInt( br.readLine() );    // int a 중 int만 삭제
   System.out.println( "a : " + 100/a );       // a가 지역변수( try )라서 a라는 방을 찾을수가 없다.
  } catch( IOException e )
  {
   e.printStackTrace();
  } catch( NumberFormatException e )
  {
   System.out.println( "숫자만 입력하세요" );
  } catch( ArithmeticException e )
  {
   System.out.println( "0으로 나누면 안됩니다" );
  } finally
  {
   System.out.println( "프로그램 끝" );
  }
 }
}

Posted by cdprkr2077
|