Throw string as exception : throw « Statement « Visual C++ .NET






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);
   }
}

   
  








Related examples in the same category

1.Rethrow Exception
2.Throw Derived Exception
3.Throw gcnew exception