Mega Code Archive

 
Categories / Visual C++ .NET / Statement
 

Throw string as exception

#include "stdafx.h" using namespace System; public ref class MyClass { public:    static void TrySomething()    {       throw gcnew String("Error that throws string!");    } }; int main() {    try    {       MyClass::TrySomething();    }    catch(String^ s)    {       Console::WriteLine(s);    } }