Inheriting from System.Exception or System.ApplicationException?(dotneat.net)

submitted by iloireiloire(310) 4 years, 5 months ago

What do you do?

3 comments |category: |Views: 27

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by yesthatmcgurkyesthatmcgurk(4063) 4 years, 5 months ago 0

So very very wrong. The article suggests THROWING an application exception, not inheriting as the title suggests. And as an application exception should crash the program (i.e., no catch should be attempted as the application cannot carry on in a safe manner), throwing them in improper circumstances can be harmful.

Rule of thumb for exceptions:
Throw exceptions only when your code has encountered an error and cannot continue.
If an exception exists that applies, throw it (i.e., ArgumentNullException, InvalidOperationException)
If one doesn't, create a custom exception that extends from System.Extension.
If there is no possibility for recovering from your error (and you know this to a certainty) throw an application exception.

Rule of thumb for catching exceptions:
The lower you are in the call stack, the less likely you will be able to handle an exception.
If you can't handle it, don't catch it.
If you need to add context to an exception thrown by an internal-to-your-class routine, you should: catch, wrap in a new exception and throw that.
It is better to crash your application than catch System.Exception. That's right, slacker.

Reply

posted by JudahGabrielJudahGabriel(814) 4 years, 5 months ago 0

mcgurk said it all, and very well said might I add.

Reply

posted by bladefistbladefist(471) 4 years, 5 months ago 0

mcgurk, what your saying sounds logical, but since its not in a blog, there is no way it can be true.

:)

Reply

information Login or create an account to comment on this story