8

I'm switching back and forth between Java and C# and one thing I miss while I'm coding in C# is the enforced exception checking (Although I admit I also find it really irritating sometimes while I'm coding in Java).

I'm aware that Exception Hunter can help you track down what exceptions a piece of code might throw but is there a free/cheaper alternative? I can't really justify £200 for this kind of software addon as it's only an annoyance rather than a major problem.

Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
  • 2
    Just let 'em go, man. You can't control the world, you know. –  Mar 17 '09 at 13:27
  • 1
    But I want to. I really want to. :p – Omar Kooheji Mar 17 '09 at 13:28
  • BTW, I +1 because I'm interested for the purposes of documentation, not because I believe I can handle each and every exception... –  Mar 17 '09 at 13:29
  • Handling every exception can lead to crazy amounts of code, but documenting an exception is like a softer version of Javas "throws" notation. I'd be happy if every API documented everything. they dont. – Omar Kooheji Mar 17 '09 at 13:45
  • 3
    Looks like Exception Hunter has been discontinued – The Diamond Z Jul 10 '12 at 10:25
  • @OmarKooheji It's not about handling every exception, it's about looking at a piece of code, knowing that it could potentially throw a FileNotFoundException and catering for that specific case if it matters. Exception Hunter just lets you make informed decisions. – Razor Jul 14 '14 at 12:21

3 Answers3

8

Yes. Run the free Microsoft Pex on your code. It will show all possible exceptions that can be thrown.

Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
  • Looks like a great tool, thanks for the link. Pity the commercial version only works with VS Team edition. – Dave Mar 18 '09 at 23:23
  • 1
    If you don't have the Team edition of VS, you can still use the tool from the command line. It generates HTML output I think. – Judah Gabriel Himango Mar 19 '09 at 16:00
  • This does not do static analysis to find thrown exceptions, it simply analyzes methods by calling them with heuristically determined parameters. It's designed for generating unit tests. http://exceptionalplugin.codeplex.com/ - this is a ReSharper plugin that'll do the job. Agent Johnson is a good complement to it - http://code.google.com/p/agentjohnsonplugin/ – Jake Petroules Jan 07 '12 at 21:50
  • @Jake - Pex does do static analysis, and yes, it will find exceptions your code can throw. (And optionally, generate unit tests from checks and exceptions.) – Judah Gabriel Himango Jan 08 '12 at 02:46
  • 1
    As far as I could tell, it won't find exceptions in the framework or in third party code, however, which Exceptional seems to do fairly well. – Jake Petroules Jan 08 '12 at 03:29
  • Ah, good point. It finds exceptions in your code, but I don't know if it finds exceptions in external code. – Judah Gabriel Himango Jan 08 '12 at 06:33
0

While I understand the enforced exceptions thing, I'm not sure how genuinely essential it is... for example, most interesting exceptions are those that you wouldn't normally include (or even expect). For example, I'm currently fighting what looks very much like a CLI bug in CF35, intermittently raising MethodMissingException from code that really does exist (emphasis: intermittently).

If you want to document your exceptions, use the ///<exception ... >...</exception> markup. For other thoughts on this theme, perhaps see Vexing Exceptions (I wonder if GhostDoc might help any?)

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
0

Get Exceptional website is one possibility. Basic idea is that you create software and all exceptions are sent to this site to your account where you can pick them up. Of course it doesn't read your code and see what exceptions are there.

I don't know if there is C# library yet but the API is not too hard.

raspi
  • 5,962
  • 3
  • 34
  • 51