473,799 Members | 3,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exceptions

How do I know which exceptions are thrown by certain methods?

For example, reading a file might throw an IO Exception, etc.

In Java, the compiler won't even let you compile unless you put your
code in try/catch blocks but the C# compiler doesn't seem to mind?

I am particularly interested in what Exceptions are thrown by
HttpWebResponse .

Is there any easy way to figure this out without rummaging through
the API everytime?

Thanks,

Drew

Nov 15 '05
22 2743
You could do it yourself, but the problem I have with relying on XML
handwritten docs is that it requires too much manual effort; and any system
that requires manual effort will eventually have bad data input into it so
it will generate incorrect results - that's worse then not doing it at all.

"WoodBeeProgram mer" <Wo************ ***@spamex.com> wrote in message
news:10******** *******@utility .isomedia.com.. .
Isn't this something "someone" (DevExpress? CodeObject?) could do-- a tool
which at design time would list the exceptions it could find from the XML
docs, at runtime could provide a logging object to get the ones that weren't doc'd correctly etc-- i'd purchase something like this..
"Dave" <no************ ****@wi.rr.com> wrote in message
news:OR******** ******@TK2MSFTN GP09.phx.gbl...
I believe we are in violent agreement on most issues. However, I maintain
that it would be useful and possible for the IDE to generate a skelton
outline of a catch handler that was correct, at least in terms of ordering the handlers from most specific to least specific. That being said it would
definitely be a non-trivial task, as the IDE would have to evaluate all

the
exceptions that could possibly be thrown within a given try block,

present
the types in a list for someone to pick the handler they wanted generated, etc.

I think the only way this becomes feasible is when static analysis tools
become better at evaluating the exceptions that could be thrown (e.g. a
statement throws an exception that is not handled locally so it bubbles

up),
and the results are baked into each method's metadata.

I believe your concern is valid, but the structuring of exceptions (i.e.

the
ordering of the handlers) is actually better done automatically as a
compiler is better-suited for evaluating object hierarchies then humans

are.

What the compiler cannot do is determine which exceptions should be caught versus allowed to bubble up, and even harder, which exceptions need
conditional testing to determine if it should bubble up. And which ones
should be swallowed and ignored, or should never be handled at all
(ExecutionEngin eException, etc). Or which ones are actually part of

program
flow control (this is actually bad practice but some library

implementations
were poorly done and require this). And, of course, the actual handling of the exception needs to be written and tested.

The main disagreement I have is that I do not feel it is worthwhile to use XML as a means of documenting this. It is way too error prone and
version-dependent - if it is done by hand then it is probably going to be wrong. I want it baked into the metadata as part of a compilation phase so that it is always correct and up-to-date (and automatic), and when

changing
assembly versions I automatically get the correct information. It also

makes
it possible for intelligent code to use reflection to extract useful
exception-related information.

"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
> The subject of how to best implement catch handlers (and when to throw)
is
> actually far more complex then this - this is just scratching the

surface.
> There is no consensus on where the catch block should be, which

exceptions
> should be caught, which allowed to bubble up the call stack, how to
> categorize exceptions (e.g. between technical and data/business

logic), etc.

This is the crux of my statement. And you're mirroring my sentiments

exactly
when you say that this is only scratching the surface. That's why I

believe
that having the IDE auto-generate the catch statements is of limited use.
It
isn't just a matter, as you say in the first paragraph, of the details

of the implementation of the handler being left up to you (the programmer), but
the entire structure and grouping of the exceptions is also an issue. For example, let's say a particular method throws a potential of seven custom exception instances and all of those exception types inherit from
ApplicationExce ption. Knowing that ApplicationExce ptions and their
derivatives indicate non-fatal app-specific problems, the programmer

chooses
to simply display a message box with the localized exception message
and a statement that the operation cannot be completed. In a scenario where the IDE generates all seven catch statements (for just this one method),
the programmer would just end up deleting all seven blocks and writing a block that catches ApplicationExce ption anyway. This also doesn't account for the
fact that this feature doesn't tell the programmer that those
exceptions inherited ApplicationExce ption in the first place.

On the other hand, if all you want (as has been posted here by several
people) is a simple list of exceptions thrown by a method, that is
acheivable. The XML docs allow for an <exception> tag. So, as long as the classes and methods are DOCUMENTED (emphesis for people who don't like to document their code! :-) ) it is easy for anyone to build an IDE
add-in that
can look this information up. The add-in can provide a table of

exceptions and even drill into the document for the specific type exception class

via
a
link (this tag allows a "cref" attribute back to the exception class
itself). Nice pet project if anyone wants to take it up.



Nov 15 '05 #21
I don't know anything about obfuscation except that I would think if it
obfuscated the actual meaning of the IL it would render it meaningless.

"Brad Williams" <sp**@wcsoft.co m> wrote in message
news:O7******** ******@TK2MSFTN GP09.phx.gbl...
"Dave" wrote:
That being said it would
definitely be a non-trivial task, as the IDE would have to evaluate all

the
exceptions that could possibly be thrown within a given try block, ...


Is this really possible? Can't IL code be obfuscated (by tools) to the
point that you simply cannot statically evaluate which op-codes are "part
of" a given method? I don't know, just suspicious.

Brad Williams

Nov 15 '05 #22

"Dave" <no************ ****@wi.rr.com> wrote in message
news:eN******** ******@TK2MSFTN GP11.phx.gbl...

"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message
news:ux******** ********@tk2msf tngp13.phx.gbl. ..
Not going to disagree with you there. I brought up the XML doc file, not
becuase it's a good idea, but simply because it is the ONLY place the
information currently exists (if it exists at all).
Agreed. It would be a way to do it given current technology.
However, let's look at the trade-off for such a solution now. Your

programs
get much bigger (if this follows the attributes meta data design, we're
talking about serialized instances of some exception info class being
injected into the meta data for every member),


Sure, but that's just the size of the assembly and the metadata within

it - the actual IL should not be affected by this.
and the only benefit you get
is a decent listing of exceptions (and possibly the auto-generated order, etc).
I think this would be an extremely powerful and useful feature. You could
easily and instantly use it as a reference into what exceptions you expect
to be thrown from within a given try block. It's more then evaluating a
method, it would have to evaluate all the methods within a try block to be
useful.

Well, the first step is to write a static tool that can analyze IL and
determine what exceptions can be thrown. This is likely to be a very
complicated piece of code and would be written best as an external(IE
not-compiler) application, atleast until the compiler is able to accept post
IL generation plugins(like thats ever going to happen). Ideally an output
metadata file from such a tool would be used in the ide(similar to how Xml
Docs work), instead of requiring all compilers for all langauges to
implement such code.
I'm not sure everyone would agree the trade-off is worthwhile. So now
you get people wanting to turn it off! Which means you will now have

members
that lack exception information - which in turn brings us right back to
where we were :-)

LOL! Well, if I had a telescope that could see clear across the universe

all I would see is the back of my own head but it would be an interesting
journey :-)

Nov 15 '05 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
5295
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem is that when an exception is raised, the destruction of locals appears to be deferred to program exit. Am I missing something? Is this behaviour by design? If so, is there any reason for it? The only rationale I can think of is to speed up...
21
2239
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the exceptions that can be raised in a Python function, or in any of the functions it calls, etc.? /Dan
26
2920
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal belief is that checked exceptions should be required in .NET. I find that many others share the same views as I do. It is extremely frustrating to have to work around this with hacks like Abstract ADO.NET and CLRxLint (which still don't solve the...
9
2342
by: Gianni Mariani | last post by:
I'm involved in a new project and a new member on the team has voiced a strong opinion that we should utilize exceptions. The other members on the team indicate that they have either been burned with unmaintainable code (an so are now not using exceptions). My position is that "I can be convinced to use exceptions" and my experience was that it let to code that was (much) more difficult to debug. The team decided that we'd give...
6
2833
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally block, just in case there might be an exception? i.e. is it ok performance-wise to pepper pieces of code with try..catch..finally blocks that must be robust, in order that cleanup can be done correctly should there be an exception?
14
3482
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a public member with a return type that is derived from System.Exception? I understand the importance of having clean, concise code that follows widely-accepted patterns and practices, but in this case, I find it hard to blindly follow a standard...
8
2260
by: cat | last post by:
I had a long and heated discussion with other developers on my team on when it makes sense to throw an exception and when to use an alternate solution. The .NET documentation recommends that an exception should be thrown only in exceptional situations. It turned out that each of my colleagues had their own interpretation about what an "exceptional situation" may actually be. First of all, myself I’m against using exceptions extensively,...
1
2392
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I look for when evaluating someone's code is a try/catch block. While it isn't a perfect indicator, exception handling is one of the few things that quickly speak about the quality of code. Within seconds you might discover that the code author...
2
2969
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It only lists NotImplementedException in the Exceptions section. (Note that it does mention WebException in the Remarks section, but who knows if this is always the case for such classes, and thus perhaps they can't be trusted to always list these, and...
0
6505
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like NullPointerException or ArrayIndexOutOfBoundsException. All of these extend the basic class Exception. In general, you can sort Exceptions into two groups: Checked and unchecked Exceptions. Checked Exceptions are checked by the compiler at compilation time. Most...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.