473,657 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exceptions in Business Classes

Hi all,

I am trying to decide how to best handle exceptions in Business Classes. For
example, there are times when public properties have valid ranges of values
and enumerations are not feasible.

What is the best way to handle these? Throw an exception such as an
ApplicationExce ption? Do you handle it differently if the property will be
bound to UI Control?

Any hints, pointers, or guidance is greatly appreciated!

Cheers,

Knut
Nov 16 '05 #1
10 2286
Hi Knut,

"Knut Vonheim" <vo*****@msn.co m> wrote in message
news:OL******** ******@tk2msftn gp13.phx.gbl...
Hi all,

I am trying to decide how to best handle exceptions in Business Classes. For example, there are times when public properties have valid ranges of values and enumerations are not feasible.

What is the best way to handle these? Throw an exception such as an
ApplicationExce ption? Do you handle it differently if the property will be
bound to UI Control?

Any hints, pointers, or guidance is greatly appreciated!


In the specific example you give, I would use
System.Argument OutOfRangeExcep tion. I would also suggest that you avoid
using ApplicationExce ption. The problem with ApplicationExce ption is that
it's too generic. There's no reasonable case (that I can see) for handling
an ApplicationExce ption any differently than the base Exception class. A
recent post in Brad Abrams' blog points this out (very good blog, btw):

http://blogs.msdn.com/brada/archive/.../25/96251.aspx

Regards,
Daniel
Nov 16 '05 #2
Daniel,

thanks for the input! I am looking into your suggestion and reading up on
the link.

The one thing I will do is to sure all my exceptions have the same base
class. I have a suspicion the reason Microsoft is recommending using
application exception class is some future change they will make. However,
as pointed out in the blog, as long as they are from the same class the
change is easy to make at that time.

Thanks again!

Cheers,

Knut
"Daniel Pratt" <ko************ ******@hotmail. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Knut,

"Knut Vonheim" <vo*****@msn.co m> wrote in message
news:OL******** ******@tk2msftn gp13.phx.gbl...
Hi all,

I am trying to decide how to best handle exceptions in Business Classes.

For
example, there are times when public properties have valid ranges of

values
and enumerations are not feasible.

What is the best way to handle these? Throw an exception such as an
ApplicationExce ption? Do you handle it differently if the property will be bound to UI Control?

Any hints, pointers, or guidance is greatly appreciated!


In the specific example you give, I would use
System.Argument OutOfRangeExcep tion. I would also suggest that you avoid
using ApplicationExce ption. The problem with ApplicationExce ption is that
it's too generic. There's no reasonable case (that I can see) for handling
an ApplicationExce ption any differently than the base Exception class. A
recent post in Brad Abrams' blog points this out (very good blog, btw):

http://blogs.msdn.com/brada/archive/.../25/96251.aspx

Regards,
Daniel

Nov 16 '05 #3
Hi Knut,

"Knut Vonheim" <vo*****@msn.co m> wrote in message
news:eJ******** ******@tk2msftn gp13.phx.gbl...
Daniel,

thanks for the input! I am looking into your suggestion and reading up on
the link.

The one thing I will do is to sure all my exceptions have the same base
class. I have a suspicion the reason Microsoft is recommending using
application exception class is some future change they will make. However,
as pointed out in the blog, as long as they are from the same class the
change is easy to make at that time.


Creating a common base class for all your exceptions is certainly your
option, but you should know that the same people who told you to inherit all
your exceptions from a common base class (i.e. ApplicationExce ption) are now
saying don't bother; Inherit from System.Exceptio n instead. Krystof Cwalina
(Program Manager for the .NET CLR) writes:

"Well-designed exception hierarchies are wide, not very deep, and
contain only those exceptions for which there is a programmatic scenario for
catching."

The ApplicationExce ption class isn't about protecting against future
changes. Rather it's a decision the designers of the .NET framework wouldn't
make if they had the chance to do it over again. Hindsight 20-20 and all
that.

Regards,
Daniel
Nov 16 '05 #4
Daniel,

thanks for the input! I am looking into your suggestion and reading up on
the link.

The one thing I will do is to sure all my exceptions have the same base
class. I have a suspicion the reason Microsoft is recommending using
application exception class is some future change they will make. However,
as pointed out in the blog, as long as they are from the same class the
change is easy to make at that time.

Thanks again!

Cheers,

Knut
"Daniel Pratt" <ko************ ******@hotmail. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi Knut,

"Knut Vonheim" <vo*****@msn.co m> wrote in message
news:OL******** ******@tk2msftn gp13.phx.gbl...
Hi all,

I am trying to decide how to best handle exceptions in Business Classes.

For
example, there are times when public properties have valid ranges of

values
and enumerations are not feasible.

What is the best way to handle these? Throw an exception such as an
ApplicationExce ption? Do you handle it differently if the property will be bound to UI Control?

Any hints, pointers, or guidance is greatly appreciated!


In the specific example you give, I would use
System.Argument OutOfRangeExcep tion. I would also suggest that you avoid
using ApplicationExce ption. The problem with ApplicationExce ption is that
it's too generic. There's no reasonable case (that I can see) for handling
an ApplicationExce ption any differently than the base Exception class. A
recent post in Brad Abrams' blog points this out (very good blog, btw):

http://blogs.msdn.com/brada/archive/.../25/96251.aspx

Regards,
Daniel

Nov 16 '05 #5
Hi Knut,

"Knut Vonheim" <vo*****@msn.co m> wrote in message
news:eJ******** ******@tk2msftn gp13.phx.gbl...
Daniel,

thanks for the input! I am looking into your suggestion and reading up on
the link.

The one thing I will do is to sure all my exceptions have the same base
class. I have a suspicion the reason Microsoft is recommending using
application exception class is some future change they will make. However,
as pointed out in the blog, as long as they are from the same class the
change is easy to make at that time.


Creating a common base class for all your exceptions is certainly your
option, but you should know that the same people who told you to inherit all
your exceptions from a common base class (i.e. ApplicationExce ption) are now
saying don't bother; Inherit from System.Exceptio n instead. Krystof Cwalina
(Program Manager for the .NET CLR) writes:

"Well-designed exception hierarchies are wide, not very deep, and
contain only those exceptions for which there is a programmatic scenario for
catching."

The ApplicationExce ption class isn't about protecting against future
changes. Rather it's a decision the designers of the .NET framework wouldn't
make if they had the chance to do it over again. Hindsight 20-20 and all
that.

Regards,
Daniel
Nov 16 '05 #6
Hi Knut,

Do you still have any concern on this issue?

Please feel free to let me know. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #7
Jeffrey,

I am working through the documentation on interfaces and CollectionBase.

I guess my question was a little broad, but I did receive some pointers to
documentation so I am working through it.

If I have more specific questions I will post in this forum.

Thanks again for following up, though!

Cheers,

Knut
""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in message
news:9s******** *****@cpmsftngx a06.phx.gbl...
Hi Knut,

Do you still have any concern on this issue?

Please feel free to let me know. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #8
Hi Knut,

Do you still have any concern on this issue?

Please feel free to let me know. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #9
Jeffrey,

I am working through the documentation on interfaces and CollectionBase.

I guess my question was a little broad, but I did receive some pointers to
documentation so I am working through it.

If I have more specific questions I will post in this forum.

Thanks again for following up, though!

Cheers,

Knut
""Jeffrey Tan[MSFT]"" <v-*****@online.mi crosoft.com> wrote in message
news:9s******** *****@cpmsftngx a06.phx.gbl...
Hi Knut,

Do you still have any concern on this issue?

Please feel free to let me know. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #10

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

Similar topics

10
231
by: Knut Vonheim | last post by:
Hi all, I am trying to decide how to best handle exceptions in Business Classes. For example, there are times when public properties have valid ranges of values and enumerations are not feasible. What is the best way to handle these? Throw an exception such as an ApplicationException? Do you handle it differently if the property will be bound to UI Control?
2
3762
by: ulrich schumacher | last post by:
Hi ASP.NET 2.0 Professionals, I've got a question concerning the new ASP.NET 2.0 DataBinding with object oriented business classes: Example: There are two business classes in my domain model: public class Language
2
1137
by: Ronald S. Cook | last post by:
So I have a table "Employee" and wish to have a business class "Employee". This was possible before LINQ. But now that I am generating a .dbml for the LINQ DataContext, it "takes over" those names for its classes. I'd hate to have to name my business classes "EmployeeClass" or some other non-ideal convention. Any thoughts? Thanks,
1
2117
by: Swathika | last post by:
Hi, Sometimes, you never get chance to learn 'Advanced Design Concepts and Real-time Scenarios' from institutes or through book-learning. But, in my blog, I have gathered some of the amazing Design concepts and practical scenarios in J2EE. Design Concepts: http://strutsjavainterviewquestions.blogspot.com/2008/07/design-level-concepts-in-j2ee.html
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.