ASP.NET Basics Part 10: Making Exceptions - Digging Deeper
(Page 11 of 12 )
In addition to what you've already seen, you can also add a couple of extra Page directives to your code to assist in debugging rogue scripts. The first of these is the Debug directive - it allows the programmer to view those sections of the code where the error might have occurred. To understand how this works, consider the following example:
<% @ Page Debug="true" %>
<script
language="c#" runat="server">
void Page_Load()
{
// create five-element array
string [] desserts =
new string[5];
// try to access the eighth element of the
array
desserts[7] = "tiramisu";
}
</script>
<html>
<head></head>
<body>
</body>
</html>
Here's what the output might look like:

You can also toss in the Trace directive, to view a list of environment variables with their current values. Here's an example:
<% @ Page Trace="true" %>
<script
language="c#" runat="server">
void Page_Load()
{
<P align=left>
<P align=left> string [] desserts = new string[5];
<P align=left> desserts[0] = "tiramisu";
<P align=left>
<P align=left>}
</script>
<html>
<head></head>
<body>
</body>
</html>
And here's the output:

Next: Endgame >>
More ASP.NET Articles
More By Harish Kamath (c) Melonfire