A.17. Chapter 17

A.17.1.

A.17.1.1.
A.17.1.1.1. Exercise 1 solution

Debugging is the process of watching your code execute in the development environment, investigating variables and looking into objects in order to understand the execution path of your code, looking for bugs with the aim to fix them. Debugging usually takes place at development time in your Visual Web Developer IDE.

Tracing, on the other hand, provides you with information on the run-time execution of your code. As discussed in this chapter, you can use tracing to get information about events that fire and the order they fire in. Additionally, you can add your own information to the trace. Since disabling tracing through configuration greatly minimizes the performance overhead associated with it, you can leave your trace calls in the code, making it easy to disable and enable tracing whenever you need it.

A.17.1.1.2. Exercise 2 solution

The best way to stop a possible exception from ending up in the user interface is to wrap your code in a Try/Catch block. That way you can display an error message to the user in case something goes wrong. Your code could end up looking like this:

VB.NET

Try
  ' Execute code here to send an e-mail or write to a file.
Catch ex As Exception
  lblErrorMessage.Text = "Something went wrong while executing the requested operation"
End Try

C#

try
{
  // Execute code here to send an e-mail or write to a file.
}
catch (Exception ex)
{ lblErrorMessage.Text = "Something went wrong while executing ...

Get Beginning ASP.NET 3.5: In C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.