VC try-catch捕获定义自己的exception

/*---------------Exception.h--------------------------*/

#pragma once

class CMyException

{

public:

       int m_ErrorCode;

       CString m_Message;

       CMyException(int ErrorCode,CString Message)

       {

             m_ErrorCode = ErrorCode;

             m_Message = Message;

       }

};


/*--------------xxxx.cpp------------------------*/

#include "Exception.h"

....

try

{

     throw(CMyException(2,_T(" error")));

}

catch(CMyException &e)

{

       code = e.m_ErrorCode;

       str = e.m_Message;

}


你可能感兴趣的:(VC try-catch捕获定义自己的exception)