Solved

where do exceptions need to be declared?

Posted on 2004-08-10
1
214 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now