自定义异常

#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;
}
原文地址:https://www.cnblogs.com/ebel/p/2763004.html