Solved

where do exceptions need to be declared?

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove greater than sign 3 67
VB.Net How to Exit Sub - Exit Form??? 5 57
converto datetime always changes format 9 35
Printing 1 50
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

10 Experts available now in Live!

Get 1:1 Help Now