21

I am looking for a list of possible exceptions in c#, c++, vb.net, j# and jscript. The problem is that some sites show me a list of 20 exceptions whereas some other site shows me a list of 39 exceptions. Can anyone please give me a proper information on this?

Pavani gaddam
  • 287
  • 1
  • 2
  • 7
  • 1
    At least for C++, there is no such thing. You can pretty much thrown anything. – Mat Jul 07 '12 at 16:42
  • 2
    There is no such list. In all .NET language you can define your own exception classes. How do you suggest to list the ones people all over the world created? – Oded Jul 07 '12 at 16:42
  • I interpret this question as a duplicate of http://stackoverflow.com/q/6676021/241211 – Michael Mar 21 '17 at 20:06

2 Answers2

28

If you're looking for a list of exceptions that the .Net framework can throw, this article has a bunch of them. I don't know where you're pulling those specific numbers from and I don't know what you hope to accomplish by knowing all of the exceptions (including ones you'll likely never see).

48klocs
  • 6,073
  • 3
  • 27
  • 34
  • 1
    A shorter, albeit older, and (IMO) slightly more useful list is here: [Common .NET Exception Types](http://blogs.msdn.com/b/brada/archive/2005/03/27/402801.aspx) – kmote Jun 03 '14 at 23:07
12

There are loads of exceptions declared by the .NET framework - and other code (including your own) can create more. There are certainly more than 39.... look at the documentation for System.Exception and you'll see near the bottom a list of all the direct known subclasses just in the .NET framework.

Basically, it's not useful to know "all the exceptions" - what's important is which exceptions can be thrown by code you are executing, and in particular which exceptions you should really try to handle (rather than those which should either kill the process or just make the request fail in a server environment).

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 26
    I understand the whish to know whish exceptions are in the framework by default. Just think about it: You have something (e.g. a not found value). Then I would say: Use an already existing exception, and not a new one. Search for the existing can be hard, a new one like ThisSpecificThingIsNotFoundException is easier. So alist would indeed help to find something useful. – Offler Jan 10 '13 at 15:15
  • 2
    In particular, it's the [Choosing standard exceptions](https://learn.microsoft.com/en-us/dotnet/api/system.exception?redirectedfrom=MSDN&view=netframework-4.7.2#choosing-standard-exceptions) section of the [`System.Exception`](http://msdn.microsoft.com/en-us/library/system.exception.aspx) page. – Evgeni Sergeev Feb 10 '19 at 03:18