|
|
|
| Non-WTF Job: C++ Developer at Good Grievance (Ronkonkoma, NY) |
| « Jan-48 | Halifax Bank Security » |
Hannes writes, "I'm currently working on maintaining rewriting an application from the early days of ASP.NET (c. 2001) to be all AJAXy and Web 2.0. One of the first things I stumbled over when I first fired up the debugger was a strange exception - the RedirectException - that got thrown on almost every page. Sometimes, it was thrown more than once in the page lifecycle, but it never made it up to the front-end.
"I quickly found out the developer didn't quite get the concept of exceptions.
try
{
if (!isCustomer)
{
-- snip lots of code to process a new order --
throw new RedirectException("/Orders/NewOrderShipping.aspx")
}
else if (isQuickOrder)
{
-- snip more order processing code --
throw new RedirectException("/Orders/Confirm.aspx")
}
else
{
-- snip even more order processing code --
throw new RedirectException("/Orders/SelectShipping.aspx")
}
}
catch (RedirectException rEx)
{
Response.Redirect(rEx.Message);
}
|
he probably did this because .Net throws an exception if you do a redirect inside a try block.
You have to either redirect with the 'endResponse' flag set to false, or catch a ThreadAbort exception and ignore it. |
Re: The RedirectException
2008-04-07 08:52
•
by
Matt
(unregistered)
|
GOTOs don't kill applications- Programmers kill applications. |
| « Jan-48 | Halifax Bank Security » |