Search code examples
c#try-catchthrowunhandled-exception

throw new exception("Test"); does not throw my text


throw new Exception("Test");

only Throws Window

I can't get my Text in there...

I also tried

throw new ArgumentException("Test");

and with a try catch and without.

But it is my written throw that makes the window.

Edit: Im working my way around so it is not possible that the throw comes.


Solution

  • You will need to catch the exception and extract the message to display.

    try
    {
         //Your code here
    }
    catch(Exception e)
    {
         var message = e.Message;
         MessageBox.Show(message);
    }