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.

Ortund
  • 8,095
  • 18
  • 71
  • 139
  • Use the debugger and look at the `InnerException` property. What does it say? – Jeroen Vannevel May 09 '14 at 15:26
  • Can't use the debugger... It closes down as soon as the first chance exception is thrown – Ortund May 09 '14 at 15:27
  • Something in your `catch` block is re-entering EF and causing a nested exception. Review that code, especially all the property getters or setters that may appear innocuous but could have side effects. – Frédéric Hamidi May 09 '14 at 15:29
  • 1
    Catch-em-all exceptions handling is very dangerous, you'll also catch the exceptions that you should never ignore. Like the kind that can get your program to terminate. The reported exit code is a pretty nasty one, there's no reasonable guess what could cause it. – Hans Passant May 09 '14 at 16:00

1 Answers1

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.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • None of my `[x] Thrown` properties are checked – Ortund May 09 '14 at 15:32
  • @Ortund: Have you expanded all of them? – Thomas Weller May 09 '14 at 15:32
  • oh I see there's a lot more... question is do I uncheck every single one of them or do I just uncheck a specific one (which one)? – Ortund May 09 '14 at 15:39
  • @Ortund, what about `System.Data.EntityException`? ;) – Frédéric Hamidi May 09 '14 at 15:44
  • System.Data.EntityException is the one I got deliberately when testing the error handling in my catch block. That's getting handled perfectly, except that execution terminates before I see the error on the website... have a look at this http://dev.loganyoung.za.net/first-chance-exception.zip – Ortund May 09 '14 at 15:59