Solved

where do exceptions need to be declared?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

19 Experts available now in Live!

Get 1:1 Help Now