ChrisJJ
ChrisJJ

Reputation: 2302

How can I get 'Break when an exception is User-unhandled' to work as advertised?

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.

Upvotes: 2

Views: 132

Answers (1)

Brian from state farm
Brian from state farm

Reputation: 2896

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

Upvotes: 1

Related Questions