0

I will simplify the example, so let's say we have Page A, Page B and Page C

  1. Page A goes with base.OnInit() on page B,
  2. Page B throws an exception and will be redirected with Server.Transfer to Page C.
  3. Page C has a try / catch, where the exception should be catched.

I've been trying with Server.GetLastError(), has brought nothing (GetLastErros is null). How can you solve it and deal without adding <customErrors> in web.config?

The interesting thing is that when I'm debugging in Page C, I can see the variable $exception, which is set correctly.

Image -> http://www.picfront.org/d/8EeT

Thank you very much.

user1323408
  • 23
  • 1
  • 6

2 Answers2

0

Your Page C doesn't know anything about exceptions in Page B. The exception that is thrown in Page B is handled there.

I guess the $exception you're seeing in Page C is a non-public member of this pages stack trace.

To have your Page C act as a generic error handler, you'd have to hand over the information about the exception. You could do this in a querystring param, but I doubt this will be an easy maintainable solution.

Maybe using a Master Page, providing a generic event handler could offer a better solution instead of a dedicated page but I haven't tried this.

Filburt
  • 17,626
  • 12
  • 64
  • 115
0

Did you use below event in your Web Page/Content Page/BasePage.

protected override void OnError(EventArgs e)
{
     base.OnError(e);
}

Did you use Application_Error in Global.asax file?

void Application_Error(object sender, EventArgs e)
{
      // Code that runs when an unhandled error occurs
}
Nilish
  • 1,066
  • 3
  • 12
  • 26