Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find exception names (in intellisense) availible to throw in VS2008

One thing I find very frustrating with C# is when I find some issue and I want to throw a meaningful exception. I find it very difficult to find those exceptions in intellisense. There is no Exception namespace, so I cant list all exceptions via intellisense without digging around looking for the exception.

I am not looking to create my own exceptions, I am only trying to see if there are any other options than googling an exception to find its namespace so I can use it.

like image 436
Jake1164 Avatar asked Jan 17 '23 01:01

Jake1164


2 Answers

For the most part, this is bad practise. There are a small handful of exceptions that you should reuse (InvalidOperation, NullReference, ArgumentException, a few others). But you should not, for example, throw SqlException yourself - because you don't know what the framework might do with it.

Creating your own exception hierarchy adds meaning to your application at times of error. Reusing exceptions that have already-understood meanings leads to confusion - loss of meaning.

like image 86
Dan Puzey Avatar answered Jan 23 '23 16:01

Dan Puzey


You can browse the entire Exception Class Tree in object Browser. Look for System.Exception and then click derived types. not 100% sure if all of them are there but the most of them are there for sure. System.Exception -> Derived types (also in the root of the System.Excecption tree)

like image 36
Freeman Avatar answered Jan 23 '23 15:01

Freeman