The Artima Developer Community
Sponsored Link

.NET Buzz Forum
What's wrong with this code? (#3) - Answer

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eric Gunnerson

Posts: 1006
Nickname: ericgu
Registered: Aug, 2003

Eric Gunnerson is a program manager on the Visual C# team
What's wrong with this code? (#3) - Answer Posted: Nov 21, 2004 5:49 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Eric Gunnerson.
Original Post: What's wrong with this code? (#3) - Answer
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Eric Gunnerson
Latest Posts From Eric Gunnerson's C# Compendium

Advertisement

Here's the discussion for the my last post.

I liked Matthew's response:

...don't throw "Exception" since you are not supposed to catch "Exception." Anybody handling exceptions thrown by this code would have to catch Exception and ignore asynchronous exceptions (like OutOfMemoryException) at the same time, which is not easy.

To expand a bit, if you wrap in a class like Exception, you force the user to write something like:

try
{
   account.UpdateBalance();
}
catch (Exception e)
{
   if (e.InnerException.GetType() == typeof(DatabaseException))
   {
      // handle the exception here
   }
   else
   {
      throw;
   }
}

This is really ugly, and if the user forgets the final "throw", the exception gets swallowed.

I also liked Steve's comment:

I don't like the fact that the exception message exposes both my account number and the account balance. If this exception text made it all the way back to the client, the current message seems like a privacy/security hole.

There are also likely things that need to be done to make the database part more robust, though that wasn't what I was intending to illustrate.

Read: What's wrong with this code? (#3) - Answer

Topic: Computer Language Architecture :-) Previous Topic   Next Topic Topic: WSCF sneak preview: command line interface

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use