Visual Studio Hacks [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Visual Studio Hacks [Electronic resources] - نسخه متنی

Andrew Lockhart

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Hack 38. Customize Visual Studio's Reaction to Exceptions

Exceptions are a sometimes-frustrating part of
debugging and developing. You can configure Visual Studio to deal
differently with certain exceptions.

When debugging a program in
Visual Studio, a number of situations may cause the debugger to enter
break mode. When the debugger enters break mode, program execution is
suspended, allowing youthe developerthe opportunity to
examine and change the program variables. With Visual Studio 2005,
you can even alter the program's underlying source
code when in break mode and have the program continue with the edited
source.

A common way that break mode is entered is through breakpoints
[Hack #36] . Another way
that break mode is
regularly entered is when an exception is raised that is not handled
by your application. Any exception that bubbles up out of your user
code will cause the Visual Studio debugger to display information
about the exception. While you will likely always want to be notified
of an unhandled exception when debugging, you may want to break when
an exception is thrown, regardless of whether or not
it's handled. Visual Studio can be easily customized
to break immediately when a particular type of exception is thrown.


5.4.1. Use the Exceptions Dialog Box


To
customize Visual
Studio's behavior when encountering exceptions, go
to Debug Exceptions or press

Ctrl-Alt-E (Debug.Exceptions). This will
display the Exceptions dialog, shown in Figure 5-16.


Figure 5-16. Exceptions dialog

The Exceptions dialog allows you to specify Visual
Studio's behavior when encountering an exception of
a specific type. As discussed earlier, the default behavior is to
continue when the exception is thrown and to break into the debugger
if the exception is not handled. To modify these settings for a
particular exception type, simply choose the exception type from the
tree of exceptions and customize the radio buttons, indicating the
debugger's behavior.


The Express versions of Visual
Studio 2005 do not offer the complete debugging experience provided
by the full version of Visual Studio 2005. At the time of this
writing, the Express versions allow specifying the exception behavior
only for all exceptions, not for specific ones
as shown in the Exceptions dialog in Figure 5-16.

Understand that changing the setting for a particular exception
modifies the behavior for any of those derived
exception types whose Use Parent Setting option is selected. By
default, all derived exceptions have this Use Parent Setting checked,
which means that, by default, changing the behavior of an exception
will propagate those changes to its derived exceptions.


5.4.2. Add Custom Exceptions



The Exceptions dialog allows you to
change the debugger's behavior when working with
system-defined exceptions, but you may want to tailor the behavior of
custom exception types you have created. To accomplish this, select
the topmost item in the tree of exceptionsCommon Language
Runtime Exceptionsand click the Add button. This will display
a dialog prompting you to enter the name of your custom exception
(see Figure 5-17). The exception name is case
insensitive, but be sure to enter the fully qualified name of your
exception, including the namespace.


Figure 5-17. Enter the name of your custom exception

Once a custom exception has been added to the list, you can remove it
by selecting the exception and clicking the Delete button; you can
remove all custom exceptions by clicking the Clear All button.


5.4.3. Quickly Finding Exception Names


While
the Exceptions dialog lists the Common
Runtime Language exceptions in an easy-to-navigate tree, there may be
times when you don't know where in the tree the
exception resides, or you may know the name of the exception and
don't want to have to scroll through the tree
interface. Fortunately, the Exceptions dialog offers a Find button
that, when clicked, will prompt you for the name, or part of the
name, of the exception.

Once you have entered the exception name and click OK, the Exceptions
dialog will highlight those exceptions in the tree that match your
search. You can click the Find Next button to enumerate through the
matches.

Scott Mitchell


/ 172