Steady Blog

23. 예외 처리 본문

Programing/C++

23. 예외 처리

우유먹고쑥 2012. 9. 4. 00:03

*예외처리

     디버깅 기법중 하나.


void ch12_08()
{
     int a,b;
     cout<<"두 개의 숫자 입력 : ";
     cin>>a>>b;
     cout<<"a/b의 몫은 : "<<a/b<<endl;
     cout<<"a/b의 나머지는 : "<<a%b;
}

 

////////////////////////////////

void ch12_09()
{
     int a,b;

up:                     //Lable(레이블)
     cout<<"두 개의 숫자 입력 : ";
     cin>>a>>b;

     if(b==0)
     {
          system("cls");
          cout<<"입력오류, 다시 입력하세요."<<endl;
          goto up;        //up: 이 있는 곳으로 이동.
     }
     else 
     {
          cout<<"a/b의 몫은 : "<<a/b<<endl;
          cout<<"a/b의 나머지는 : "<<a%b<<endl;
     }

}

/////////////////////////////////

void ch12_10()
{
      int a,b;

      cout<<"두 개의 숫자 입력 : ";
      cin>>a>>b;
      try
      {
            if(b==0)
                  throw b;
            cout<<"a/b의 몫은 : "<<a/b<<endl;
            cout<<"a/b의 나머지는 : "<<a%b<<endl;
      }
      catch(int exception)
      {
              cout<<exception<<"입력오류, 다시 입력하세요."<<endl;

      }

}


 

'Programing > C++' 카테고리의 다른 글

22. 연산자 오버로딩 - 정리 필요.  (0) 2012.09.04
21. 상속 part 2 ---정리 필요함.  (0) 2012.09.04
20. 상속  (0) 2012.09.04
19. 정적변수  (0) 2012.09.04
18. const변수  (0) 2012.09.04