⋮
<customErrors mode="modeValue"
defaultRedirect="errorPage.aspx" />
⋮
</system.web>
</configuration>
The defaultRedirect attribute of the customErrors element is used to specify
the page that’s used to report errors. We can then choose whether this error page
is shown to everybody, to nobody, or only to users who access the site from an-
other network using the mode attribute. The possible values for the mode attribute
are:
On
When mode is On, ASP.NET uses user-defined custom error pages,
instead of its default error page, for both local and remote users.
Off
When mode has a value of Off, ASP.NET uses its default error
page for both local and remote users. The customErrors element
has no effect when mode is set to Off.
RemoteOnly
When mode has the RemoteOnly value, the ASP.NET error page
is shown only to local users, and the custom error page is shown
to remote users. RemoteOnly is the default value, and is generally
the safest option during development. If the defaultRedirect
attribute is present, remote visitors will see the page mentioned;
otherwise, they’ll see a generic error that doesn’t contain debug-
ging information.
Handling Exceptions Locally
As you can see, unless you handle any exceptions that are raised in your code
yourself, they’ll be caught by the debugger. If you’re not running the code within
Visual Web Developer, the exceptions will be caught by the ASP.NET runtime,
which displays the errors in the browser.
Additionally, C# and VB enable you to handle runtime errors using the
Try-Catch-Finally construct.
The basic syntax of Try-Catch-Finally is as follows:
Visual Basic
Try
' Code that could generate the exception that you want to handle
213
Handling Exceptions Locally