2

How can I get Break when an exception is User-unhandled to reliably work as advertised https://archive.is/090KL?

Here is an example of it working and another of it failing:

public partial class MainForm : Form
{
    public MainForm()
    {
        InitializeComponent();

          LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0,0,100,100),Color.Blue, Color.White,angle:0);
          brush.WrapMode = WrapMode.Clamp; // Causes Unhandled exception alert, offering break
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        {
            LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, 100, 100), Color.Blue, Color.White, angle: 0);
            brush.WrapMode = WrapMode.Clamp; // Fails to break
        }
    }
}

There are no user exception handlers in this program. This example is Platform target x86 and running under Windows 7.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
ChrisJJ
  • 2,191
  • 1
  • 25
  • 38
  • 1
    Crystal ball says that you are using Windows 7. Review the workarounds in [this post](http://stackoverflow.com/a/4934010/17034). – Hans Passant Oct 19 '15 at 13:54
  • I am using Windows 7 Info added. Thanks for the workarounds. The only one applicable http://i.imgur.com/2gKYkjP.png works http://i.imgur.com/JAWKLQq.png ...but at the cost of catching user-handled exceptions too, of course. – ChrisJJ Oct 19 '15 at 14:07
  • Hmm, hard to see what's wrong with getting the debugger to stop when the exception is thrown. It is hardly the "only one applicable", removing the jitter forcing and updating your machine to Win10 are very decent alternatives. – Hans Passant Oct 19 '15 at 14:15
  • @Damien_The_Unbeliever, Thanks - done. – ChrisJJ Oct 20 '15 at 02:33
  • @Hans, what's wrong with getting the debugger to stop when the exception is thrown it that it does so even on user-handled exceptions, in contrast to "Break when an exception is User-unhandled". – ChrisJJ Oct 20 '15 at 02:35
  • @ChrisJJ We are not "question interferers" - you, on the other hand, are tag misuser ;) Your intentions are irrelevant in the context of tag usage rules that are in force here. Please follow them - in the mean time I've fixed your code highlighting :) – BartoszKP Dec 08 '15 at 15:10
  • @ BartoszK "We are not "question interferers"". Are you speaking for all of them?? :) "in the mean time I've fixed your code highlighting :)" Thanks! – ChrisJJ Dec 10 '15 at 00:02

1 Answers1

1

Using Visual Studio 2012 and your code example on Windows 7 if I modify the Main() static thread it caused the exception to be thrown.

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
    //Added this line and corresponding method
    Application.ThreadException += Application_ThreadException;

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
}
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Brian from state farm
  • 2,825
  • 12
  • 17