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 22 2740
The Java feature is called "checked exceptions" and C# doesn't have it.
I used to have a link from the C# developers about why they decided not to
include this feature, but I have misplaced. However, the decision was based
on this article by Bruce Eckle http://www.mindview.net/Etc/Discussi...ckedExceptions
I tend to agree with Bruce here. I used to hold his C++ books in high
regards, and I taught Java using his Thinking In Java book.
If you want to know what exceptions are specifically thrown by a class, you
can look up the MSDN class reference for the class. You can also document
your own exceptions from your class by including it in the xml docs. Dynamic
help should help you avoid having to look all over the place for it. Since
the data is in the XML docs (or should be), it would be a nice IDE feature
to hit a button and "include catch block for..." , which would add templates
for all the ones it could discover. Going to have to wait for that feature
though. But even that's of limited use since you might want to group catch
blocks, or use more generic ones.
-Rob Teixeira [MVP]
"Drew" <so*****@hotmai l.com> wrote in message
news:el******** ******@TK2MSFTN GP12.phx.gbl... 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
This is a very interesting discussion about checked exceptions.
I guess I just always took checked exceptions for granted in Java.
There are many times when I lazily just caught the exception and didn't do
much with it.
Now I'm thinking it might not be so bad without them. ;)
However, I do like your suggestion about the IDE having the capability
to generate the try/catch blocks. At the least, I would like it to show me
what exceptions are generated by a certain class. Perhaps in properties?
Drew
"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message
news:eu******** ******@TK2MSFTN GP09.phx.gbl... The Java feature is called "checked exceptions" and C# doesn't have it. I used to have a link from the C# developers about why they decided not to include this feature, but I have misplaced. However, the decision was
based on this article by Bruce Eckle http://www.mindview.net/Etc/Discussi...ckedExceptions I tend to agree with Bruce here. I used to hold his C++ books in high regards, and I taught Java using his Thinking In Java book.
If you want to know what exceptions are specifically thrown by a class,
you can look up the MSDN class reference for the class. You can also document your own exceptions from your class by including it in the xml docs.
Dynamic help should help you avoid having to look all over the place for it. Since the data is in the XML docs (or should be), it would be a nice IDE feature to hit a button and "include catch block for..." , which would add
templates for all the ones it could discover. Going to have to wait for that feature though. But even that's of limited use since you might want to group catch blocks, or use more generic ones.
-Rob Teixeira [MVP]
"Drew" <so*****@hotmai l.com> wrote in message news:el******** ******@TK2MSFTN GP12.phx.gbl... 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
Hi all,
With VS.NET IDE you can use Ctrl+Alt+E (cor click the Exceptions..
line on the debug menu)when you have an open project to list all of
the exceptions that a system can throw (organized by platform and then
library). This can be followed up with a specific search of the MSDN
to isolate the actual exception details.
~~~~~~~~~~~~~
Tommie Carter
--
"Drew" <so*****@hotmai l.com> wrote in message news:<Ok******* *******@TK2MSFT NGP09.phx.gbl>. .. This is a very interesting discussion about checked exceptions.
I guess I just always took checked exceptions for granted in Java. There are many times when I lazily just caught the exception and didn't do much with it.
Now I'm thinking it might not be so bad without them. ;)
However, I do like your suggestion about the IDE having the capability to generate the try/catch blocks. At the least, I would like it to show me what exceptions are generated by a certain class. Perhaps in properties?
Drew
"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message news:eu******** ******@TK2MSFTN GP09.phx.gbl... The Java feature is called "checked exceptions" and C# doesn't have it. I used to have a link from the C# developers about why they decided not to include this feature, but I have misplaced. However, the decision was based on this article by Bruce Eckle http://www.mindview.net/Etc/Discussi...ckedExceptions I tend to agree with Bruce here. I used to hold his C++ books in high regards, and I taught Java using his Thinking In Java book.
If you want to know what exceptions are specifically thrown by a class, you can look up the MSDN class reference for the class. You can also document your own exceptions from your class by including it in the xml docs. Dynamic help should help you avoid having to look all over the place for it. Since the data is in the XML docs (or should be), it would be a nice IDE feature to hit a button and "include catch block for..." , which would add templates for all the ones it could discover. Going to have to wait for that feature though. But even that's of limited use since you might want to group catch blocks, or use more generic ones.
-Rob Teixeira [MVP]
"Drew" <so*****@hotmai l.com> wrote in message news:el******** ******@TK2MSFTN GP12.phx.gbl... 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
reL IDE support for exceptions...Th at would be a great feature and it has
been asked for many times, but it will probably be a long time before we see
it (lots of practical details that have not been ironed out). For now we
have to rely on the written documentation and the problem is that this is
often misleading. It may be that a given method itself only throws a small
number of exceptions, but the API you call can invoke other methods that
throw entirely different exceptions, so you may wind up catching exceptions
that are not included in the official documentation. Make sure you have a
backstop catch handler somewhere, and hooking the unhandled exception event
is also usually a good idea; you can't recover from the exception here but
you can at least log it.
"Drew" <so*****@hotmai l.com> wrote in message
news:Ok******** ******@TK2MSFTN GP09.phx.gbl... This is a very interesting discussion about checked exceptions.
I guess I just always took checked exceptions for granted in Java. There are many times when I lazily just caught the exception and didn't do much with it.
Now I'm thinking it might not be so bad without them. ;)
However, I do like your suggestion about the IDE having the capability to generate the try/catch blocks. At the least, I would like it to show
me what exceptions are generated by a certain class. Perhaps in properties?
Drew
"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message news:eu******** ******@TK2MSFTN GP09.phx.gbl... The Java feature is called "checked exceptions" and C# doesn't have it. I used to have a link from the C# developers about why they decided not
to include this feature, but I have misplaced. However, the decision was based on this article by Bruce Eckle http://www.mindview.net/Etc/Discussi...ckedExceptions I tend to agree with Bruce here. I used to hold his C++ books in high regards, and I taught Java using his Thinking In Java book.
If you want to know what exceptions are specifically thrown by a class, you can look up the MSDN class reference for the class. You can also
document your own exceptions from your class by including it in the xml docs. Dynamic help should help you avoid having to look all over the place for it.
Since the data is in the XML docs (or should be), it would be a nice IDE
feature to hit a button and "include catch block for..." , which would add templates for all the ones it could discover. Going to have to wait for that
feature though. But even that's of limited use since you might want to group
catch blocks, or use more generic ones.
-Rob Teixeira [MVP]
"Drew" <so*****@hotmai l.com> wrote in message news:el******** ******@TK2MSFTN GP12.phx.gbl... 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
That's really the biggest problem with the IDE auto-generating catch
statements - it doesn't know HOW you want to handle them.
For example, you may choose to group all possible ApplicationExce ptions (all
exceptions derived from ApplicationExce ption) in one block, and all generic
Exceptions in another, or you might want to handle all ApplicationExce ptions
in one block, while handling other individual exceptions in their own
blocks. The permutations and sometimes possible number of exceptions is why
i mentioned in my post that a feature like this is of somewhat limited use.
-Rob Teixeira [MVP]
"Dave" <no************ ****@wi.rr.com> wrote in message
news:um******** ******@TK2MSFTN GP10.phx.gbl... reL IDE support for exceptions...Th at would be a great feature and it has been asked for many times, but it will probably be a long time before we
see it (lots of practical details that have not been ironed out). For now we have to rely on the written documentation and the problem is that this is often misleading. It may be that a given method itself only throws a small number of exceptions, but the API you call can invoke other methods that throw entirely different exceptions, so you may wind up catching
exceptions that are not included in the official documentation. Make sure you have a backstop catch handler somewhere, and hooking the unhandled exception
event is also usually a good idea; you can't recover from the exception here but you can at least log it.
How about a compile time option that would show which methods
throw exceptions and it could possibly warn you about potential
problems without requiring you to implement exception handling?
Perhaps you could select what types of warnings you want.
(e.g. checkbox: warn me about unhandled I/O exceptions, etc.)
Does this already exist?
Drew
"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message
news:uC******** ******@tk2msftn gp13.phx.gbl... That's really the biggest problem with the IDE auto-generating catch statements - it doesn't know HOW you want to handle them. For example, you may choose to group all possible ApplicationExce ptions
(all exceptions derived from ApplicationExce ption) in one block, and all
generic Exceptions in another, or you might want to handle all
ApplicationExce ptions in one block, while handling other individual exceptions in their own blocks. The permutations and sometimes possible number of exceptions is
why i mentioned in my post that a feature like this is of somewhat limited
use. -Rob Teixeira [MVP]
"Dave" <no************ ****@wi.rr.com> wrote in message news:um******** ******@TK2MSFTN GP10.phx.gbl... reL IDE support for exceptions...Th at would be a great feature and it
has been asked for many times, but it will probably be a long time before we see it (lots of practical details that have not been ironed out). For now we have to rely on the written documentation and the problem is that this
is often misleading. It may be that a given method itself only throws a
small number of exceptions, but the API you call can invoke other methods that throw entirely different exceptions, so you may wind up catching exceptions that are not included in the official documentation. Make sure you have
a backstop catch handler somewhere, and hooking the unhandled exception event is also usually a good idea; you can't recover from the exception here
but you can at least log it.
On 2004-01-02, Tom Carter <tc********@hot mail.com> wrote: Hi all,
With VS.NET IDE you can use Ctrl+Alt+E (cor click the Exceptions.. line on the debug menu)when you have an open project to list all of the exceptions that a system can throw (organized by platform and then library). This can be followed up with a specific search of the MSDN to isolate the actual exception details.
That's fairly useless though, if you're wonder about what exceptions
may be thrown by a particular method of a particular class.
--
David
dfoster at
hotpop dot com
On 2004-01-02, Rob Teixeira [MVP] <RobTeixeira@ @> wrote: That's really the biggest problem with the IDE auto-generating catch statements - it doesn't know HOW you want to handle them. For example, you may choose to group all possible ApplicationExce ptions (all exceptions derived from ApplicationExce ption) in one block, and all generic Exceptions in another, or you might want to handle all ApplicationExce ptions in one block, while handling other individual exceptions in their own blocks. The permutations and sometimes possible number of exceptions is why i mentioned in my post that a feature like this is of somewhat limited use.
Just my two cents, but I think it would be very useful. For example,
click on a function, hit ctrl-alt-whatever, and up pops a tree-view
dialog box with all the exceptions that might be thrown by that function
or any functions it calls, organized by class structure. For version
two, select any node in the tree and click the 'Create catch block'
button to add the catch block.
But the "generate catch block" is secondary, the main thing is that it
would be nice to KNOW what exceptions might be thrown at a given time,
rather than just guessing, which is all you're really doing by relying
on the documentation. I agree with Eckel et. al. about the problems
with Checked Exceptions, but I wonder if there isn't a useful middle
ground, where thrown exceptions are specified somehow (for example, with
attributes in the metadata) but aren't required to be caught by the
caller. That at least would allow the IDE and compiler to provide
better support for them.
--
David
dfoster at
hotpop dot com
> Just my two cents, but I think it would be very useful. For example, click on a function, hit ctrl-alt-whatever, and up pops a tree-view dialog box with all the exceptions that might be thrown by that function or any functions it calls, organized by class structure.
I agree. This would be very useful.
I don't think we necessarily need an auto generate feature, but just being
able to see what exceptions might be thrown would be a big help to me.
Drew This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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
|
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...
|
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...
|
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?
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
| |
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...
|
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...
| |