473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Component exception design question...

Hi, all. I'm looking for a "straw poll" of opinions on two ways to
implement part of an exception hierarchy. Forgive the silly example I
offer, but its what came to mind on the fly as I decided how to
illustrate the question.

Let's assume you have an application called "FruitStore," with a
component called "FruitInventory," and it has a method
AddFruit("fruitname"). The relevant rule for this discussion is that
each "fruitname" in the inventory must be unique.

The broader application FruitStore, which maintains a variety of other
information, has a generic exception called DuplicateDataException.
Upon detection of a duplicate fruit in the AddFruit method, the method
has two options:

1. It can throw the generic DuplicateDataException.
2. It can define and throw its own exception, called
DuplicateFruitException.

Consideration: The DuplicateDataException allows for a string message
as a parameter in its constructor that might say "Duplicate fruit
"fruitname" detected."

Which, if either, would the learned ones here advocate?

Please reply to group...email is long dead.

Thanks,
David
Nov 15 '05 #1
1 1277
I think it all depends on whether the user would care about the difference.
The big thing to avoid is forcing people to write:

catch (DuplicateDataException e)
{
if (e.ToString().IndexOf("fruit") != -1)
{
// handle the exception here
}
}

as this is very bad code. In fact, my example has a common error that will
lead to less robust code.

Being able to figure this out is in general a hard problem, so I tend
towards having more exceptions if you are uncertain about what the user
might want.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"David Whitney" <in*********@hotmail.com> wrote in message
news:63**************************@posting.google.c om...
Hi, all. I'm looking for a "straw poll" of opinions on two ways to
implement part of an exception hierarchy. Forgive the silly example I
offer, but its what came to mind on the fly as I decided how to
illustrate the question.

Let's assume you have an application called "FruitStore," with a
component called "FruitInventory," and it has a method
AddFruit("fruitname"). The relevant rule for this discussion is that
each "fruitname" in the inventory must be unique.

The broader application FruitStore, which maintains a variety of other
information, has a generic exception called DuplicateDataException.
Upon detection of a duplicate fruit in the AddFruit method, the method
has two options:

1. It can throw the generic DuplicateDataException.
2. It can define and throw its own exception, called
DuplicateFruitException.

Consideration: The DuplicateDataException allows for a string message
as a parameter in its constructor that might say "Duplicate fruit
"fruitname" detected."

Which, if either, would the learned ones here advocate?

Please reply to group...email is long dead.

Thanks,
David

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Crawford | last post by:
Hi, Where would one start for this type of application: I want to create an vb.net container application that has the gives the end user the ability to install and uninstall plugins or add-in...
12
by: Chien Lau | last post by:
I had a situation occur today that's happened a number of times before and I'd like to get your take on it: Imagine... You're developing a WinForms app for a client that includes the use charts....
0
by: Jason | last post by:
What interface do I need to implement in order to get a component with a public property to show up in the data binding drop down boxes at design time in VS.net? I've tried to look just about...
0
by: David | last post by:
Hello I have made a component (MyWebForm) that inherits Page. This component have a method called 'ComponentAdded' that shows a msgbox if it is in design mode: Public Class MyWebForm Inherits...
3
by: gabe | last post by:
I have a general design question. What's a 'Best Practice' for middle tier component design? I'm thinking of a web form that contains data from multiple tables. The data is supplied from one...
6
by: **Developer** | last post by:
What does this mean: External component has thrown an exception. My program crashes after it leaves a subroutine. What I see during debugging is when I press F11 at the End Sub statement
2
by: AMDRIT | last post by:
Hello everyone, I have created a custom component and one of its properties is a class object with it's own properties. During runtime, I can assign values to the class object properties just...
3
by: JohnDeHope3 | last post by:
First let me say that I understand that Asp.Net wraps my exception in an HttpUnhandledException. I have found a lot of discussion about that on the web, which was informative, but not helpful. Let...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.