Mega Code Archive

 
Categories / Visual C++ .NET / Statement
 

Catch All exceptions

#include "stdafx.h" using namespace System; ref class MyDerivedException : public ApplicationException{ public:     MyDerivedException( String ^err ); }; MyDerivedException::MyDerivedException(String ^err) : ApplicationException(err){ } ref class MyException { }; void main(){     for (int i = 0; i < 4; i++){         try{             if (i == 1)                 throw gcnew ApplicationException("\tBase Exception");             else if (i == 2)                 throw gcnew MyDerivedException("\tMy Derived Exception");             else if (i == 3)                 throw gcnew MyException();         }catch (ApplicationException ^e){             Console::WriteLine(e->Message);         }catch (...){             Console::WriteLine("\tMy Exception");         }     } }