Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Olbert 87 posts 117 karma points
    Nov 28, 2009 @ 07:04
    Mark Olbert
    0

    Catching Exceptions on a Master Page

    I'm trying to catch, and handle, some database exceptions on a masterpage I've created. I've tried adding the following to the masterpage codebehind:

            public void PageError( object sender, EventArgs e )
            {
                int i = 9;
                i++;
            }

            protected override void HandleException( PageExceptionArgs args )
            {
                base.HandleException(args);
            }

    Neither of these methods ever get called.

    Is Umbraco intercepting exceptions at a deeper level, before the page "sees" them? Or is this lack of firing due to the fact that the code is on a masterpage, not a page?

    - Mark

  • Mark Olbert 87 posts 117 karma points
    Nov 28, 2009 @ 17:07
    Mark Olbert
    1

    It seems the issue is not with Umbraco, but rather with how masterpages work. The OnError() handler for a masterpage doesn't get called when there's an error on the page it defines.

    However, you can add an event handler (on every page load) to call a Page_Error routine which in turn calls OnError():

            protected override void OnLoad( EventArgs e )
            {
                base.OnLoad(e);

                this.Page.Error += new EventHandler(Page_Error);
            }

            protected void Page_Error( object sender, EventArgs e )
            {
            }

    Which works well enough.

    - Mark

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies