First chance exception when handling exceptions

1

The way I'm handling exceptions is to set values for controls on my master page from the client page where the exception occurs:

    private void deleteUser(int userid)
    {
        try
        {
            ImajUser u = new ImajUser(userid, true);
            u.Delete();

            lblerr.Text = "User was deleted successfully.";
            lblerr.ForeColor = System.Drawing.Color.Green;
        }
        catch (Exception ex)
        {
            this.Master.ErrorTitle.Text = "Delete User";
            this.Master.ErrorMessage.Text = String.Format("Error actioning request: [ {0} ]", ex.Message);
            this.Master.pnlErrorBG.Visible = true;
            this.Master.pnlErrorModal.Visible = true;

        }
    }

When i test this (last time I shut down the database and tried a Delete), my catch block executes without fault, but I get a first chance exception and the debugger stops completely:

A first chance exception of type 'System.Data.EntityException' occurred in System.Data.Entity.dll
The program '[2108] WebDev.WebServer40.EXE: Managed (v4.0.30319)' has exited with code -2147023895 (0x800703e9).

I've never seen this before. I don't know what causes it and I don't know how to fix it either...

Any help will be greatly appreciated!

EDIT

The properties I'm setting for access to the master page's controls are:

    public virtual Label ErrorTitle { get { return lblErrorAction; } }
    public virtual Label ErrorMessage { get { return lblErrorMessage; } }
    public virtual Panel pnlErrorBG { get { return ErrorBackground; } }
    public virtual Panel pnlErrorModal { get { return pnlErrorModal; } }

These reference the controls:

    <asp:Panel runat="server" id="ErrorBackground" visible="false"> </asp:Panel>
    <asp:Panel runat="server" id="ErrorModal" visible="false">
        <asp:Label runat="server" ID="lblErrorAction" CssClass="lblerrortitle"></asp:Label>
        <asp:Label runat="server" ID="lblErrorMessage"></asp:Label>
        <asp:Button runat="server" ID="btnErrorAction" CssClass="button" Text="Retry" OnClick="btnErrorAction_Click" />
    </asp:Panel>

EDIT 2
So I tried moving the controls to the page where the exception actually occurs and that worked 100% whereas using controls on the master page causes the error.

c#
exception-handling
first-chance-exception
asked on Stack Overflow May 9, 2014 by Ortund • edited May 9, 2014 by Ortund

1 Answer

1

This is a Visual Studio setting in Debug / Exceptions. The [x] Thrown properties tells the debugger to stop on first chance exceptions. Uncheck the checkbox to stop only on second chance exceptions.

Screenshot

BTW: first chance exceptions do not terminate a process. Only second chance exceptions do. So you should be able to continue by pressing the "Play" button (Continue) again or use the F5 key.

answered on Stack Overflow May 9, 2014 by Thomas Weller

User contributions licensed under CC BY-SA 3.0