ASP.NET Basics Part 10: Making Exceptions - A Custom Job
(Page 4 of 12 )
You can also specify the custom error page on a per-script basis, redirecting the client to different pages depending on which script caused the exception. In order to do this, simply add the ErrorPage property in the Page directive, as in the example below:
<% @ Page ErrorPage="divbyzero.aspx"
%>
<script language="c#" runat="server">
void Page_Load()
{
<P align=left>
<P align=left>int a = 19;
int b = 0;
int c = a/b;
<P align=left>
<P align=left>}
</script>
<html>
<head></head>
<body>
<asp:label
id="output" runat="server"
/>
</body>
</html>
In this case, when the exception occurs, the browser will jump to "divbyzero.aspx" instead of the default page defined in "web.config". This mechanism thus lets you specify a custom error page to catch all exceptions, yet override it on a per-script basis if you need to.

Next: You Throw(), I'll Catch() >>
More ASP.NET Articles
More By Harish Kamath (c) Melonfire