Feature Request: Design-time Exception Checking

Checked exceptions have been a topic of heated debate amongst C# developers. Coming from a Java upbringing, I have really missed the compiler complaining if I don't cover an exception or explicitly throw it. I realize that requiring checked exceptions as a language constraint can cause its own set of headaches. However, when developing in C# I still miss some exceptions at development time that I would have caught without effort in Java.

It would be nice to be presented with a list of possible exceptions within a method at design-time. I feel this feature would greatly improve my initial code quality. I wouldn’t have to stumble across as many run-time situations to test my code. It seems to me that this functionality would fill the gap between Sun and Microsoft’s conflicting view on the subject.

Is a feature like this within the realm of possibility for ReSharper?

Cheers!

-Brian

20 comments
Comment actions Permalink

Brian,

We've been discussing the feature for almost a half of an year :) It will
require some reasonable efforts to implement and I think we'll get back to
the issue after the release of 2.0. But frankly speaking, I'm not so excited
about checked exceptions, because it makes code too wordy in most cases.

--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

I have thoroughly mixed emotions regarding exception coverage. On the one
hand, I would love to be able to click on a method or property to obtain a
list of exceptions that it (or its base methods or properties) throw so I
can intelligently determine which exceptions to catch without having to walk
stacks of XML documents or MSDN help. On the other hand, being forced to
catch every exception a method and its base methods throw can make the code
overly complex to the point that I have more catch blocks than real code. In
some cases, I really don't care about the exceptions in the method I'm
writing because they are intended to be handled in the calling layer.

--
Lothan


"Brian Rumburg" <no_mail@jetbrains.com> wrote in message
news:12333307.1126626049493.JavaMail.javamailuser@localhost...

Checked exceptions have been a topic of heated debate amongst C#
developers. Coming from a Java upbringing, I have really missed the
compiler complaining if I don't cover an exception or explicitly throw it.
I realize that requiring checked exceptions as a language constraint can
cause its own set of headaches. However, when developing in C# I still
miss some exceptions at development time that I would have caught without
effort in Java.

>

It would be nice to be presented with a list of possible exceptions within
a method at design-time. I feel this feature would greatly improve my
initial code quality. I wouldn?t have to stumble across as many run-time
situations to test my code. It seems to me that this functionality would
fill the gap between Sun and Microsoft?s conflicting view on the subject.

>

Is a feature like this within the realm of possibility for ReSharper?

>

Cheers!

>

-Brian



0
Comment actions Permalink

In many cases you can figure out which exceptions are thrown by actually
looking at the code. Barring the situations where the exception thrown is
determined in runtime, by reflection or by being passed the exception to
throw from the outside, you can determine which exceptions need to be caught
by analyzing the code.
You can even recognize where exceptions are caught and not thrown upwards...

This way you can identify cases where the exceptions caught are of the wrong
type, not thrown or could be replaced by a derived class exception...

This could be a real cool feature... Such feature would merit an entire
release...


0
Comment actions Permalink

So I ran across this blog http://www.bluebytesoftware.com/blog/CommentView.aspx?guid=b5eeea0a-dd9a-42e4-a3f6-08a4807e488e

Looks like this guy is attemting to detect exceptions thrown by API calls and compile a list in HTML format. There are some limitations listed in his post:



A sample output can be found here:
http://www.bluebytesoftware.com/code/04/10/27/NetExceptions/default.html

Regarding your comment:
+But frankly speaking, I'm not so excited
about checked exceptions, because it makes code too wordy in most cases.+

I agree with your statement here. I think what we're trying to avoid here is manditory, compiler enforced checked exceptions (a la Java). I myself feel it is a bit wordy / strict. All we're looking for is a design-time helper to tell us what CAN be thrown by our calls. This would aid in the decision of whether to catch an excption or just let it percolate up the stack.

0
Comment actions Permalink

How about using the information about thrown exceptions from the documentation
comments? We could warn if the method invoked has some exception documented
in its comment which is neither handled nor documented as thrown by the invoking
method. What do you think?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Checked exceptions have been a topic of heated debate amongst C#
developers. Coming from a Java upbringing, I have really missed the
compiler complaining if I don't cover an exception or explicitly throw
it. I realize that requiring checked exceptions as a language
constraint can cause its own set of headaches. However, when
developing in C# I still miss some exceptions at development time that
I would have caught without effort in Java.

It would be nice to be presented with a list of possible exceptions
within a method at design-time. I feel this feature would greatly
improve my initial code quality. I wouldn?t have to stumble across as
many run-time situations to test my code. It seems to me that this
functionality would fill the gap between Sun and Microsoft?s
conflicting view on the subject.

Is a feature like this within the realm of possibility for ReSharper?

Cheers!

-Brian



0
Comment actions Permalink

Hello Valentin,

I think it would be better to retrieve the information about possible exceptions
thrown by a method by
analysing the method's body.


Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

How about using the information about thrown exceptions from the
documentation comments? We could warn if the method invoked has some
exception documented in its comment which is neither handled nor
documented as thrown by the invoking method. What do you think?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>> Checked exceptions have been a topic of heated debate amongst C#
>> developers. Coming from a Java upbringing, I have really missed the
>> compiler complaining if I don't cover an exception or explicitly
>> throw it. I realize that requiring checked exceptions as a language
>> constraint can cause its own set of headaches. However, when
>> developing in C# I still miss some exceptions at development time
>> that I would have caught without effort in Java.
>>
>> It would be nice to be presented with a list of possible exceptions
>> within a method at design-time. I feel this feature would greatly
>> improve my initial code quality. I wouldn?t have to stumble across
>> as many run-time situations to test my code. It seems to me that
>> this functionality would fill the gap between Sun and Microsoft?s
>> conflicting view on the subject.
>>
>> Is a feature like this within the realm of possibility for ReSharper?
>>
>> Cheers!
>>
>> -Brian
>>


0
Comment actions Permalink

I think it would be better to retrieve the information about possible
exceptions
thrown by a method by
analysing the method's body.


How about virtual/abstract methods?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Hello Valentin,

I think it would be better to retrieve the information about possible
exceptions
thrown by a method by
analysing the method's body.
Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>> How about using the information about thrown exceptions from the
>> documentation comments? We could warn if the method invoked has some
>> exception documented in its comment which is neither handled nor
>> documented as thrown by the invoking method. What do you think?
>>
>> Valentin Kipiatkov
>> Chief Scientist, Vice President of Product Development
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>> Checked exceptions have been a topic of heated debate amongst C#
>>> developers. Coming from a Java upbringing, I have really missed the
>>> compiler complaining if I don't cover an exception or explicitly
>>> throw it. I realize that requiring checked exceptions as a language
>>> constraint can cause its own set of headaches. However, when
>>> developing in C# I still miss some exceptions at development time
>>> that I would have caught without effort in Java.
>>>
>>> It would be nice to be presented with a list of possible exceptions
>>> within a method at design-time. I feel this feature would greatly
>>> improve my initial code quality. I wouldn?t have to stumble across
>>> as many run-time situations to test my code. It seems to me that
>>> this functionality would fill the gap between Sun and Microsoft?s
>>> conflicting view on the subject.
>>>
>>> Is a feature like this within the realm of possibility for
>>> ReSharper?
>>>
>>> Cheers!
>>>
>>> -Brian
>>>


0
Comment actions Permalink

Hello Valentin,

is it a common practice for C# projects to specify the exceptions thrown
by an abstract method in
documentation comments?

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>> I think it would be better to retrieve the information about possible
>> exceptions
>> thrown by a method by
>> analysing the method's body.

How about virtual/abstract methods?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>> Hello Valentin,
>>
>> I think it would be better to retrieve the information about possible
>> exceptions
>> thrown by a method by
>> analysing the method's body.
>> Regards,
>> Dmitry Shaporenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>> How about using the information about thrown exceptions from the
>>> documentation comments? We could warn if the method invoked has some
>>> exception documented in its comment which is neither handled nor
>>> documented as thrown by the invoking method. What do you think?
>>>
>>> Valentin Kipiatkov
>>> Chief Scientist, Vice President of Product Development
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>>> Checked exceptions have been a topic of heated debate amongst C#
>>>> developers. Coming from a Java upbringing, I have really missed
>>>> the compiler complaining if I don't cover an exception or
>>>> explicitly throw it. I realize that requiring checked exceptions
>>>> as a language constraint can cause its own set of headaches.
>>>> However, when developing in C# I still miss some exceptions at
>>>> development time that I would have caught without effort in Java.
>>>>
>>>> It would be nice to be presented with a list of possible exceptions
>>>> within a method at design-time. I feel this feature would greatly
>>>> improve my initial code quality. I wouldn?t have to stumble across
>>>> as many run-time situations to test my code. It seems to me that
>>>> this functionality would fill the gap between Sun and Microsoft?s
>>>> conflicting view on the subject.
>>>>
>>>> Is a feature like this within the realm of possibility for
>>>> ReSharper?
>>>>
>>>> Cheers!
>>>>
>>>> -Brian
>>>>


0
Comment actions Permalink

You could analyze the exceptions thrown by whatever sources you see that
inherit from interfaces. I would much prefer the ability to rely on what's
in the code over what's rumored to be in the code by the docs.

It doesn't have to be slow either, as the information could be cached by
resharper...


"Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in message
news:c8a894d9762ba8c78bf776381b7a@news.intellij.net...

Hello Valentin,

>

is it a common practice for C# projects to specify the exceptions thrown
by an abstract method in
documentation comments?

>

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>>> I think it would be better to retrieve the information about possible
>>> exceptions
>>> thrown by a method by
>>> analysing the method's body.
>> How about virtual/abstract methods?
>>
>> Valentin Kipiatkov
>> Chief Scientist, Vice President of Product Development
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>> Hello Valentin,
>>>
>>> I think it would be better to retrieve the information about possible
>>> exceptions
>>> thrown by a method by
>>> analysing the method's body.
>>> Regards,
>>> Dmitry Shaporenkov
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>>> How about using the information about thrown exceptions from the
>>>> documentation comments? We could warn if the method invoked has some
>>>> exception documented in its comment which is neither handled nor
>>>> documented as thrown by the invoking method. What do you think?
>>>>
>>>> Valentin Kipiatkov
>>>> Chief Scientist, Vice President of Product Development
>>>> JetBrains, Inc
>>>> http://www.jetbrains.com
>>>> "Develop with pleasure!"
>>>>> Checked exceptions have been a topic of heated debate amongst C#
>>>>> developers. Coming from a Java upbringing, I have really missed
>>>>> the compiler complaining if I don't cover an exception or
>>>>> explicitly throw it. I realize that requiring checked exceptions
>>>>> as a language constraint can cause its own set of headaches.
>>>>> However, when developing in C# I still miss some exceptions at
>>>>> development time that I would have caught without effort in Java.
>>>>>
>>>>> It would be nice to be presented with a list of possible exceptions
>>>>> within a method at design-time. I feel this feature would greatly
>>>>> improve my initial code quality. I wouldn?t have to stumble across
>>>>> as many run-time situations to test my code. It seems to me that
>>>>> this functionality would fill the gap between Sun and Microsoft?s
>>>>> conflicting view on the subject.
>>>>>
>>>>> Is a feature like this within the realm of possibility for
>>>>> ReSharper?
>>>>>
>>>>> Cheers!
>>>>>
>>>>> -Brian
>>>>>
>



0
Comment actions Permalink

Hello Amir,

I agree. It seems to me that such a cache could be maintained up-to-date
without
prohibitive overhead.

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

You could analyze the exceptions thrown by whatever sources you see
that inherit from interfaces. I would much prefer the ability to rely
on what's in the code over what's rumored to be in the code by the
docs.

It doesn't have to be slow either, as the information could be cached
by resharper...

"Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in message
news:c8a894d9762ba8c78bf776381b7a@news.intellij.net...

>> Hello Valentin,
>>
>> is it a common practice for C# projects to specify the exceptions
>> thrown
>> by an abstract method in
>> documentation comments?
>> Regards,
>> Dmitry Shaporenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>>> I think it would be better to retrieve the information about
>>>> possible
>>>> exceptions
>>>> thrown by a method by
>>>> analysing the method's body.
>>> How about virtual/abstract methods?
>>>
>>> Valentin Kipiatkov
>>> Chief Scientist, Vice President of Product Development
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>>> Hello Valentin,
>>>>
>>>> I think it would be better to retrieve the information about
>>>> possible
>>>> exceptions
>>>> thrown by a method by
>>>> analysing the method's body.
>>>> Regards,
>>>> Dmitry Shaporenkov
>>>> JetBrains, Inc
>>>> http://www.jetbrains.com
>>>> "Develop with pleasure!"
>>>>> How about using the information about thrown exceptions from the
>>>>> documentation comments? We could warn if the method invoked has
>>>>> some exception documented in its comment which is neither handled
>>>>> nor documented as thrown by the invoking method. What do you
>>>>> think?
>>>>>
>>>>> Valentin Kipiatkov
>>>>> Chief Scientist, Vice President of Product Development
>>>>> JetBrains, Inc
>>>>> http://www.jetbrains.com
>>>>> "Develop with pleasure!"
>>>>>> Checked exceptions have been a topic of heated debate amongst C#
>>>>>> developers. Coming from a Java upbringing, I have really missed
>>>>>> the compiler complaining if I don't cover an exception or
>>>>>> explicitly throw it. I realize that requiring checked exceptions
>>>>>> as a language constraint can cause its own set of headaches.
>>>>>> However, when developing in C# I still miss some exceptions at
>>>>>> development time that I would have caught without effort in Java.
>>>>>>
>>>>>> It would be nice to be presented with a list of possible
>>>>>> exceptions within a method at design-time. I feel this feature
>>>>>> would greatly improve my initial code quality. I wouldn?t have
>>>>>> to stumble across as many run-time situations to test my code.
>>>>>> It seems to me that this functionality would fill the gap between
>>>>>> Sun and Microsoft?s conflicting view on the subject.
>>>>>>
>>>>>> Is a feature like this within the realm of possibility for
>>>>>> ReSharper?
>>>>>>
>>>>>> Cheers!
>>>>>>
>>>>>> -Brian
>>>>>>


0
Comment actions Permalink

Ok, let's suppose that we can detect which exceptions are thrown by particular
method. How do we use this information then? It does not seem to be a good
idea to warn on a call to a method throwing an exception without a catch
because in many cases exceptions are to be handled on upper level. So what
should we do?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

You could analyze the exceptions thrown by whatever sources you see
that inherit from interfaces. I would much prefer the ability to rely
on what's in the code over what's rumored to be in the code by the
docs.

It doesn't have to be slow either, as the information could be cached
by resharper...

"Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in message
news:c8a894d9762ba8c78bf776381b7a@news.intellij.net...

>> Hello Valentin,
>>
>> is it a common practice for C# projects to specify the exceptions
>> thrown
>> by an abstract method in
>> documentation comments?
>> Regards,
>> Dmitry Shaporenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>>> I think it would be better to retrieve the information about
>>>> possible
>>>> exceptions
>>>> thrown by a method by
>>>> analysing the method's body.
>>> How about virtual/abstract methods?
>>>
>>> Valentin Kipiatkov
>>> Chief Scientist, Vice President of Product Development
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>>> Hello Valentin,
>>>>
>>>> I think it would be better to retrieve the information about
>>>> possible
>>>> exceptions
>>>> thrown by a method by
>>>> analysing the method's body.
>>>> Regards,
>>>> Dmitry Shaporenkov
>>>> JetBrains, Inc
>>>> http://www.jetbrains.com
>>>> "Develop with pleasure!"
>>>>> How about using the information about thrown exceptions from the
>>>>> documentation comments? We could warn if the method invoked has
>>>>> some exception documented in its comment which is neither handled
>>>>> nor documented as thrown by the invoking method. What do you
>>>>> think?
>>>>>
>>>>> Valentin Kipiatkov
>>>>> Chief Scientist, Vice President of Product Development
>>>>> JetBrains, Inc
>>>>> http://www.jetbrains.com
>>>>> "Develop with pleasure!"
>>>>>> Checked exceptions have been a topic of heated debate amongst C#
>>>>>> developers. Coming from a Java upbringing, I have really missed
>>>>>> the compiler complaining if I don't cover an exception or
>>>>>> explicitly throw it. I realize that requiring checked exceptions
>>>>>> as a language constraint can cause its own set of headaches.
>>>>>> However, when developing in C# I still miss some exceptions at
>>>>>> development time that I would have caught without effort in Java.
>>>>>>
>>>>>> It would be nice to be presented with a list of possible
>>>>>> exceptions within a method at design-time. I feel this feature
>>>>>> would greatly improve my initial code quality. I wouldn?t have
>>>>>> to stumble across as many run-time situations to test my code.
>>>>>> It seems to me that this functionality would fill the gap between
>>>>>> Sun and Microsoft?s conflicting view on the subject.
>>>>>>
>>>>>> Is a feature like this within the realm of possibility for
>>>>>> ReSharper?
>>>>>>
>>>>>> Cheers!
>>>>>>
>>>>>> -Brian
>>>>>>


0
Comment actions Permalink

Error highlighting is not the only feature that could benefit from this information.

This information could be available as e.g. a dedicated popup window available
at a
point of the method invocation - it is often very important to understand
what exceptions an invocation
of a method can throw (in particular, for deciding whether we should catch
them here or let our
caller handle them).

But even with error highlighting we could mark 'catch' clauses which catch
exceptions that
cannot actually be thrown as redundant.

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Ok, let's suppose that we can detect which exceptions are thrown by
particular method. How do we use this information then? It does not
seem to be a good idea to warn on a call to a method throwing an
exception without a catch because in many cases exceptions are to be
handled on upper level. So what should we do?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>> You could analyze the exceptions thrown by whatever sources you see
>> that inherit from interfaces. I would much prefer the ability to rely
>> on what's in the code over what's rumored to be in the code by the
>> docs.
>>
>> It doesn't have to be slow either, as the information could be cached
>> by resharper...
>>
>> "Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in
>> message news:c8a894d9762ba8c78bf776381b7a@news.intellij.net...
>>
>>> Hello Valentin,
>>>
>>> is it a common practice for C# projects to specify the exceptions
>>> thrown
>>> by an abstract method in
>>> documentation comments?
>>> Regards,
>>> Dmitry Shaporenkov
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>>>> I think it would be better to retrieve the information about
>>>>> possible
>>>>> exceptions
>>>>> thrown by a method by
>>>>> analysing the method's body.
>>>> How about virtual/abstract methods?
>>>>
>>>> Valentin Kipiatkov
>>>> Chief Scientist, Vice President of Product Development
>>>> JetBrains, Inc
>>>> http://www.jetbrains.com
>>>> "Develop with pleasure!"
>>>>> Hello Valentin,
>>>>>
>>>>> I think it would be better to retrieve the information about
>>>>> possible
>>>>> exceptions
>>>>> thrown by a method by
>>>>> analysing the method's body.
>>>>> Regards,
>>>>> Dmitry Shaporenkov
>>>>> JetBrains, Inc
>>>>> http://www.jetbrains.com
>>>>> "Develop with pleasure!"
>>>>>> How about using the information about thrown exceptions from the
>>>>>> documentation comments? We could warn if the method invoked has
>>>>>> some exception documented in its comment which is neither handled
>>>>>> nor documented as thrown by the invoking method. What do you
>>>>>> think?
>>>>>>
>>>>>> Valentin Kipiatkov
>>>>>> Chief Scientist, Vice President of Product Development
>>>>>> JetBrains, Inc
>>>>>> http://www.jetbrains.com
>>>>>> "Develop with pleasure!"
>>>>>>> Checked exceptions have been a topic of heated debate amongst C#
>>>>>>> developers. Coming from a Java upbringing, I have really missed
>>>>>>> the compiler complaining if I don't cover an exception or
>>>>>>> explicitly throw it. I realize that requiring checked
>>>>>>> exceptions as a language constraint can cause its own set of
>>>>>>> headaches. However, when developing in C# I still miss some
>>>>>>> exceptions at development time that I would have caught without
>>>>>>> effort in Java.
>>>>>>>
>>>>>>> It would be nice to be presented with a list of possible
>>>>>>> exceptions within a method at design-time. I feel this feature
>>>>>>> would greatly improve my initial code quality. I wouldn?t have
>>>>>>> to stumble across as many run-time situations to test my code.
>>>>>>> It seems to me that this functionality would fill the gap
>>>>>>> between
>>>>>>> Sun and Microsoft?s conflicting view on the subject.
>>>>>>> Is a feature like this within the realm of possibility for
>>>>>>> ReSharper?
>>>>>>>
>>>>>>> Cheers!
>>>>>>>
>>>>>>> -Brian
>>>>>>>


0
Comment actions Permalink

Oh... This is the sweet spot:

Generate Catch...

Mark a block of statements and select Generate Catch. (which in fact we
already have C-A-J with try-catch) - you are given a list of exceptions (and
base exceptions) that you can catch at that point.

This is where it gets smart. If an exception is caught and NOT rethrown, it
will not be available in the scope above the catching scope...

Since you parse the reference assemblies, this information can also be made
available to system and other assemblies....

Amir


"Valentin Kipiatkov (JetBrains)" <valentin@jetbrains.com> wrote in message
news:3fdb29a68c8b58c78c003c025bf9@news.intellij.net...

Ok, let's suppose that we can detect which exceptions are thrown by
particular method. How do we use this information then? It does not seem
to be a good idea to warn on a call to a method throwing an exception
without a catch because in many cases exceptions are to be handled on
upper level. So what should we do?



0
Comment actions Permalink

Generate Catch...

Mark a block of statements and select Generate Catch. (which in fact
we already have C-A-J with try-catch) - you are given a list of
exceptions (and base exceptions) that you can catch at that point.


Ok, that we would have. But as I understand the original request it was about
checking unhandled exception. How would we do that?

Valentin Kipiatkov
Chief Scientist, Vice President of Product Development
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Oh... This is the sweet spot:

Generate Catch...

Mark a block of statements and select Generate Catch. (which in fact
we already have C-A-J with try-catch) - you are given a list of
exceptions (and base exceptions) that you can catch at that point.

This is where it gets smart. If an exception is caught and NOT
rethrown, it will not be available in the scope above the catching
scope...

Since you parse the reference assemblies, this information can also be
made available to system and other assemblies....

Amir

"Valentin Kipiatkov (JetBrains)" <valentin@jetbrains.com> wrote in
message news:3fdb29a68c8b58c78c003c025bf9@news.intellij.net...

>> Ok, let's suppose that we can detect which exceptions are thrown by
>> particular method. How do we use this information then? It does not
>> seem to be a good idea to warn on a call to a method throwing an
>> exception without a catch because in many cases exceptions are to be
>> handled on upper level. So what should we do?
>>


0
Comment actions Permalink

>> Mark a block of statements and select Generate Catch. (which in fact
>> we already have C-A-J with try-catch) - you are given a list of
>> exceptions (and base exceptions) that you can catch at that point.

Ok, that we would have. But as I understand the original request it was
about checking unhandled exception. How would we do that?


The naive approach would be to have it as a warning. However - that would be
totally unacceptable from any aspect - performance and UI.
So I guess we would have to combine it with the Generate Catch somehow.

Maybe - Show Unhandled Exceptions when with a statement, or block of
statements, in scope and allow the following:
Catch (Catch Base)
Convert - take one exception and turn it to another.
Go to Origin (Who? What? Why?).
Go to Catcher (if one can be identified above) <-- Can be very useful
when trying to decide if anyone we know is relying on an exception we're
about to tinker with.

With a block selected you could highlight the statements that could be tried
and either catch within individual scope or the whole scope.

The catching of system exceptions (null pointer, division by 0, etc). should
be a matter of choice as you don't REALLY want to check ALL pointer access
:) So perhaps a Show System Exceptions should an option or a separate
action.

Amir



0
Comment actions Permalink

This is true in cases in which the source code is available, but this is
definitely not the case when using third-party classes that have been run
through a code corruption tool. Unfortunately, not all developers (even
commercial vendors) document the exceptions each method can throw. This
basically leaves in the position of attempting to guess or using the brute
force technique of throwing random illegal values at each method to discover
which exceptions bubble up.

Take the case of the Leadtools imaging library. It's a huge framework of
imaging classes, but they do not document or even give a hint of which
exceptions methods can throw. The only exception I see that's even
documented is RasterOcrException, but it contains a large
RasterOcrExceptionCode enumeration. Not exactly a friendly way to implement
a framework and all of the sample code catches System.Exception. uggh!

IP*Works is another example, although perhaps for the same reason. The
documentation states, "...For erred messages, the response will contain an
error code related to the failure for delivery, and the component will
thrown an exception." Which exception? I have no idea because it fails to
document any exceptions at all other than a large list of WINSOCK error
codes. This instance is a little less worrisome at the moment, though,
because we're dumping it in the trash because of its numerous bugs and
horrendous unreliability.

--
Lothan


"Amir Kolsky" <amir@xpandsoft.com> wrote in message
news:dg91oq$72h$1@is.intellij.net...

In many cases you can figure out which exceptions are thrown by actually
looking at the code. Barring the situations where the exception thrown is
determined in runtime, by reflection or by being passed the exception to
throw from the outside, you can determine which exceptions need to be
caught by analyzing the code.
You can even recognize where exceptions are caught and not thrown
upwards...

>

This way you can identify cases where the exceptions caught are of the
wrong type, not thrown or could be replaced by a derived class
exception...

>

This could be a real cool feature... Such feature would merit an entire
release...



0
Comment actions Permalink

Microsoft seems to endorse this technique of documenting exceptions in the
XML comments for each method and property (and it's the technique I use in
all classes), but I suspect you'll find it very unreliable and incomplete
because not all developers take the time to include exception information in
the comments. I just rummaged through two commercial .NET libraries that do
not include any exception documentation in the assemblies.

I suspect the only way to reliably extract exception information is to start
at method X and walk every method call through reflection to search the MSIL
for throw statements. I would love to have such a tool that can extract
this information, but this should probably be in an external application due
to the time required to walk the call trees.

--
Lothan


"Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in message
news:c8a894d9762ba8c78bf776381b7a@news.intellij.net...

Hello Valentin,

>

is it a common practice for C# projects to specify the exceptions thrown
by an abstract method in
documentation comments?

>

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>>> I think it would be better to retrieve the information about possible
>>> exceptions
>>> thrown by a method by
>>> analysing the method's body.
>> How about virtual/abstract methods?
>>
>> Valentin Kipiatkov
>> Chief Scientist, Vice President of Product Development
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>> Hello Valentin,
>>>
>>> I think it would be better to retrieve the information about possible
>>> exceptions
>>> thrown by a method by
>>> analysing the method's body.
>>> Regards,
>>> Dmitry Shaporenkov
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>>> How about using the information about thrown exceptions from the
>>>> documentation comments? We could warn if the method invoked has some
>>>> exception documented in its comment which is neither handled nor
>>>> documented as thrown by the invoking method. What do you think?
>>>>
>>>> Valentin Kipiatkov
>>>> Chief Scientist, Vice President of Product Development
>>>> JetBrains, Inc
>>>> http://www.jetbrains.com
>>>> "Develop with pleasure!"
>>>>> Checked exceptions have been a topic of heated debate amongst C#
>>>>> developers. Coming from a Java upbringing, I have really missed
>>>>> the compiler complaining if I don't cover an exception or
>>>>> explicitly throw it. I realize that requiring checked exceptions
>>>>> as a language constraint can cause its own set of headaches.
>>>>> However, when developing in C# I still miss some exceptions at
>>>>> development time that I would have caught without effort in Java.
>>>>>
>>>>> It would be nice to be presented with a list of possible exceptions
>>>>> within a method at design-time. I feel this feature would greatly
>>>>> improve my initial code quality. I wouldn?t have to stumble across
>>>>> as many run-time situations to test my code. It seems to me that
>>>>> this functionality would fill the gap between Sun and Microsoft?s
>>>>> conflicting view on the subject.
>>>>>
>>>>> Is a feature like this within the realm of possibility for
>>>>> ReSharper?
>>>>>
>>>>> Cheers!
>>>>>
>>>>> -Brian
>>>>>
>



0
Comment actions Permalink

If this could be implemented in ReSharper, the first place I'd want to use
the information is in a list that shows up when I type "catch(". Another
place that might be useful is in the tooltip that shows up when I cursor
over a method or property.

--
Lothan


"Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in message
news:c8a894d9763a98c78c03462ad636@news.intellij.net...

Error highlighting is not the only feature that could benefit from this
information.
This information could be available as e.g. a dedicated popup window
available at a
point of the method invocation - it is often very important to understand
what exceptions an invocation
of a method can throw (in particular, for deciding whether we should catch
them here or let our
caller handle them).

>

But even with error highlighting we could mark 'catch' clauses which catch
exceptions that
cannot actually be thrown as redundant.

>

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>> Ok, let's suppose that we can detect which exceptions are thrown by
>> particular method. How do we use this information then? It does not
>> seem to be a good idea to warn on a call to a method throwing an
>> exception without a catch because in many cases exceptions are to be
>> handled on upper level. So what should we do?
>>
>> Valentin Kipiatkov
>> Chief Scientist, Vice President of Product Development
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>> You could analyze the exceptions thrown by whatever sources you see
>>> that inherit from interfaces. I would much prefer the ability to rely
>>> on what's in the code over what's rumored to be in the code by the
>>> docs.
>>>
>>> It doesn't have to be slow either, as the information could be cached
>>> by resharper...
>>>
>>> "Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in
>>> message news:c8a894d9762ba8c78bf776381b7a@news.intellij.net...
>>>
>>>> Hello Valentin,
>>>>
>>>> is it a common practice for C# projects to specify the exceptions
>>>> thrown
>>>> by an abstract method in
>>>> documentation comments?
>>>> Regards,
>>>> Dmitry Shaporenkov
>>>> JetBrains, Inc
>>>> http://www.jetbrains.com
>>>> "Develop with pleasure!"
>>>>>> I think it would be better to retrieve the information about
>>>>>> possible
>>>>>> exceptions
>>>>>> thrown by a method by
>>>>>> analysing the method's body.
>>>>> How about virtual/abstract methods?
>>>>>
>>>>> Valentin Kipiatkov
>>>>> Chief Scientist, Vice President of Product Development
>>>>> JetBrains, Inc
>>>>> http://www.jetbrains.com
>>>>> "Develop with pleasure!"
>>>>>> Hello Valentin,
>>>>>>
>>>>>> I think it would be better to retrieve the information about
>>>>>> possible
>>>>>> exceptions
>>>>>> thrown by a method by
>>>>>> analysing the method's body.
>>>>>> Regards,
>>>>>> Dmitry Shaporenkov
>>>>>> JetBrains, Inc
>>>>>> http://www.jetbrains.com
>>>>>> "Develop with pleasure!"
>>>>>>> How about using the information about thrown exceptions from the
>>>>>>> documentation comments? We could warn if the method invoked has
>>>>>>> some exception documented in its comment which is neither handled
>>>>>>> nor documented as thrown by the invoking method. What do you
>>>>>>> think?
>>>>>>>
>>>>>>> Valentin Kipiatkov
>>>>>>> Chief Scientist, Vice President of Product Development
>>>>>>> JetBrains, Inc
>>>>>>> http://www.jetbrains.com
>>>>>>> "Develop with pleasure!"
>>>>>>>> Checked exceptions have been a topic of heated debate amongst C#
>>>>>>>> developers. Coming from a Java upbringing, I have really missed
>>>>>>>> the compiler complaining if I don't cover an exception or
>>>>>>>> explicitly throw it. I realize that requiring checked
>>>>>>>> exceptions as a language constraint can cause its own set of
>>>>>>>> headaches. However, when developing in C# I still miss some
>>>>>>>> exceptions at development time that I would have caught without
>>>>>>>> effort in Java.
>>>>>>>>
>>>>>>>> It would be nice to be presented with a list of possible
>>>>>>>> exceptions within a method at design-time. I feel this feature
>>>>>>>> would greatly improve my initial code quality. I wouldn?t have
>>>>>>>> to stumble across as many run-time situations to test my code.
>>>>>>>> It seems to me that this functionality would fill the gap
>>>>>>>> between
>>>>>>>> Sun and Microsoft?s conflicting view on the subject.
>>>>>>>> Is a feature like this within the realm of possibility for
>>>>>>>> ReSharper?
>>>>>>>>
>>>>>>>> Cheers!
>>>>>>>>
>>>>>>>> -Brian
>>>>>>>>
>



0
Comment actions Permalink

Which is what I was shooting for...

Amir

If this could be implemented in ReSharper, the first place I'd want to use
the information is in a list that shows up when I type "catch(". Another
place that might be useful is in the tooltip that shows up when I cursor
over a method or property.

>

--
Lothan



0
Comment actions Permalink

Out of interest, do you document only the new exceptions your code might
throw, or any exceptions that any function/library it calls might throw as
well?

Dino

"GREGORY LAW" <lothan@email.uophx.edu> wrote in message
news:dh7tuf$fgi$1@is.intellij.net...

Microsoft seems to endorse this technique of documenting exceptions in the
XML comments for each method and property (and it's the technique I use in
all classes), but I suspect you'll find it very unreliable and incomplete
because not all developers take the time to include exception information
in the comments. I just rummaged through two commercial .NET libraries
that do not include any exception documentation in the assemblies.

>

I suspect the only way to reliably extract exception information is to
start at method X and walk every method call through reflection to search
the MSIL for throw statements. I would love to have such a tool that can
extract this information, but this should probably be in an external
application due to the time required to walk the call trees.

>

--
Lothan

>
>

"Dmitry Shaporenkov (JetBrains)" <dsha@jetbrains.com> wrote in message
news:c8a894d9762ba8c78bf776381b7a@news.intellij.net...

>> Hello Valentin,
>>
>> is it a common practice for C# projects to specify the exceptions thrown
>> by an abstract method in
>> documentation comments?
>>
>> Regards,
>> Dmitry Shaporenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>>
>>>> I think it would be better to retrieve the information about possible
>>>> exceptions
>>>> thrown by a method by
>>>> analysing the method's body.
>>> How about virtual/abstract methods?
>>>
>>> Valentin Kipiatkov
>>> Chief Scientist, Vice President of Product Development
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>>> Hello Valentin,
>>>>
>>>> I think it would be better to retrieve the information about possible
>>>> exceptions
>>>> thrown by a method by
>>>> analysing the method's body.
>>>> Regards,
>>>> Dmitry Shaporenkov
>>>> JetBrains, Inc
>>>> http://www.jetbrains.com
>>>> "Develop with pleasure!"
>>>>> How about using the information about thrown exceptions from the
>>>>> documentation comments? We could warn if the method invoked has some
>>>>> exception documented in its comment which is neither handled nor
>>>>> documented as thrown by the invoking method. What do you think?
>>>>>
>>>>> Valentin Kipiatkov
>>>>> Chief Scientist, Vice President of Product Development
>>>>> JetBrains, Inc
>>>>> http://www.jetbrains.com
>>>>> "Develop with pleasure!"
>>>>>> Checked exceptions have been a topic of heated debate amongst C#
>>>>>> developers. Coming from a Java upbringing, I have really missed
>>>>>> the compiler complaining if I don't cover an exception or
>>>>>> explicitly throw it. I realize that requiring checked exceptions
>>>>>> as a language constraint can cause its own set of headaches.
>>>>>> However, when developing in C# I still miss some exceptions at
>>>>>> development time that I would have caught without effort in Java.
>>>>>>
>>>>>> It would be nice to be presented with a list of possible exceptions
>>>>>> within a method at design-time. I feel this feature would greatly
>>>>>> improve my initial code quality. I wouldn?t have to stumble across
>>>>>> as many run-time situations to test my code. It seems to me that
>>>>>> this functionality would fill the gap between Sun and Microsoft?s
>>>>>> conflicting view on the subject.
>>>>>>
>>>>>> Is a feature like this within the realm of possibility for
>>>>>> ReSharper?
>>>>>>
>>>>>> Cheers!
>>>>>>
>>>>>> -Brian
>>>>>>
>>
>>
>



0

Please sign in to leave a comment.