Solved

where do exceptions need to be declared?

Posted on 2004-08-10
1
244 Views
Last Modified: 2012-05-05
ok I'm writing an app and I'm trying to follow some guidelines and only throw new exceptions that have been derived from the exception class.

the question though.. is should I create a new file for all new exception classes that I make? if I plan on using an exception in more than one dll.. where does that normally go?

do I create a dll of nothing but exceptions that can be thrown from anywhere?
0
Comment
Question by:jayrod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
tinchos earned 125 total points
ID: 11767526
Hi jayrod

Here are some guidelines that may help you

1) You do not need to create a new file for each new exception.
You can define the exception in the same file that is thrown, in a separate file, or all exceptions in the same file.

Personally I would define the exception in a file that represents the context where the exception arises.

2) If you want to use an exception in more than one dll, I would suggest the following....

If the exception you're talking about is a general use exception, such as InvalidInputException or something like that, I would put it in a separate dll. Somewhere where you would put some classes of general use. Keep in mind that you do not need to put just exceptions there, place all general use code  you have.
After that you would need to make your dlls using that exception depend on this general-use dll.

Finally I would suggest that you derive exceptions not from the Exception class but from ApplicationException.

From MSDN

ApplicationException is thrown by a user program, not by the common language runtime. If you are designing an application that needs to create its own exceptions, derive from the ApplicationException class. ApplicationException extends Exception, but does not add new functionality. This exception is provided as means to differentiate between exceptions defined by applications versus exceptions defined by the system.

Hope this helps

Tincho
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set custom font WPF 2 25
c#, datatable, aspx 4 50
Using sample Autorize.net c# simple example 1 53
c# deserialize JSON from web service using JsonConvert 9 57
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question