Visual CSharp 1002005 A Developers Notebook [Electronic resources] نسخه متنی

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

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

Visual CSharp 1002005 A Developers Notebook [Electronic resources] - نسخه متنی

Jesse Liberty

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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







2.8. Diagnose Exceptions


The new Exception Assistant gives you a strong
head start on figuring out why your code threw an exception and what
to do about it.


2.8.1. How do I do that?


The new Visual Studio 2005 Exception
Assistant is always turned on; you don't have to do
anything special (except for throwing an exception) to call it into
action. When an exception is thrown, the editor switches to Break
mode, the statement that caused the exception is highlighted, and the
Exception Assistant leaps forward with suggestions for what to do.

Note: The Exception Assistant helps you diagnose why an exception
was thrown.

To see this at work, go back to ExamineXML, the
project you created for the "Visualize XML
Data" lab, and in the source code change the name of
the file to be read by StreamReader from
BookList.xml to
BadFileName.xml, a nonexistent file:

// using (StreamReader reader = File.OpenText(@"..\..\BookList.xml")) 
using (StreamReader reader = File.OpenText(@"..\..\BadFileName.xml"))

Run the program by pressing F5. The code will break on the line
you've changed, and the Exception Assistant will
come forward, as shown in Figure 2-22.


Figure 2-22. The Exception Assistant


At this point, you can click one of the Troubleshooting Tips to open
the appropriate Help file page, or you can click View Detail.

In this case, the problem is self-evident; the file could not be
found, and your job is only to figure out why the
OpenText method could not find your file.


2.8.2. What about...


...the View Detail link? What is that for?

Clicking the View Detail link will open the View Detail dialog box,
as shown in Figure 2-23.


Figure 2-23. The View Detail dialog box


The details in this particular case are not very helpful because the
exception is self-explanatory, but for some types of head-banging
exceptions, the Exception Snapshot panel of the View Detail window
can provide the information you need.


2.8.3. Where can I learn more?


C# Corner has a
good article on
exception handling at http://www.c-sharpcorner.com/Tutorials/ExceptionHandling101RVS.asp,
as does
O'Reilly's ONDotnet.com site at
http://www.ondotnet.com/pub/a/dotnet.2001.09/04/error_handlingl.


/ 71