473,394 Members | 1,722 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,394 software developers and data experts.

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
ApplicationException? 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 2258
Hi Knut,

"Knut Vonheim" <vo*****@msn.com> wrote in message
news:OL**************@tk2msftngp13.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
ApplicationException? 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.ArgumentOutOfRangeException. I would also suggest that you avoid
using ApplicationException. The problem with ApplicationException is that
it's too generic. There's no reasonable case (that I can see) for handling
an ApplicationException 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****************@TK2MSFTNGP12.phx.gbl...
Hi Knut,

"Knut Vonheim" <vo*****@msn.com> wrote in message
news:OL**************@tk2msftngp13.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
ApplicationException? 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.ArgumentOutOfRangeException. I would also suggest that you avoid
using ApplicationException. The problem with ApplicationException is that
it's too generic. There's no reasonable case (that I can see) for handling
an ApplicationException 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.com> wrote in message
news:eJ**************@tk2msftngp13.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. ApplicationException) are now
saying don't bother; Inherit from System.Exception 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 ApplicationException 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****************@TK2MSFTNGP12.phx.gbl...
Hi Knut,

"Knut Vonheim" <vo*****@msn.com> wrote in message
news:OL**************@tk2msftngp13.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
ApplicationException? 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.ArgumentOutOfRangeException. I would also suggest that you avoid
using ApplicationException. The problem with ApplicationException is that
it's too generic. There's no reasonable case (that I can see) for handling
an ApplicationException 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.com> wrote in message
news:eJ**************@tk2msftngp13.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. ApplicationException) are now
saying don't bother; Inherit from System.Exception 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 ApplicationException 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.microsoft.com> wrote in message
news:9s*************@cpmsftngxa06.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.microsoft.com> wrote in message
news:9s*************@cpmsftngxa06.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
Hi Knut,

Thanks for your feedback.

Yes, I hope you can find all you want through your research.

Anyway, you can feel free to post, the community will help you. 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 #11

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

Similar topics

10
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...
2
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...
2
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.