-2
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.

Henrik Wilshusen
  • 289
  • 1
  • 11
  • 3
    Throwing an exception with the message is not equal to showing a Message Box with the message. What do you want to do? If you want to show a message, use MessageBox.Show("Test") in WinForms. – Vlad Stryapko Jul 06 '17 at 09:14
  • did you try catching the exception in the "Catch" block. Also, make sure you don't have "Break on all errors" checked under visual studio settings. – Nirman Jul 06 '17 at 09:15
  • And if you want to make your own exception with custom text, you need to implement your own custom exception class that derives from Exception. Eg. https://blogs.msdn.microsoft.com/agileer/2013/05/17/the-correct-way-to-code-a-custom-exception-class/ – ainwood Jul 06 '17 at 09:23

1 Answers1

1

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);
}
David Pilkington
  • 13,528
  • 3
  • 41
  • 73