[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

where do exceptions need to be declared?

Posted on 2004-08-10
1
Medium Priority
?
255 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 500 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

Technology Partners: 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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

650 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