自定义异常

#include "stdafx.h"
#include <iostream>
using namespace std;
class MyProblem :public exception
{
public:
    MyProblem()
    {

    }
    virtual const char* what() const throw()
    {
        return "There are something wrong!\n";
    }
};
int _tmain(int argc, _TCHAR* argv[]) 
{
   try
   {
       if ("Something wrong!")
       {
           throw MyProblem();
       }
   }
   catch(const exception& e)
   {
      cerr<<e.what()<<endl;
   }
    return 0;
}

 

posted @ 2012-11-09 17:22  Ebel  阅读(118)  评论(0编辑  收藏  举报