473,325 Members | 2,442 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,325 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 2256
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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...
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.