Bad Programming: How not to use try/catch blocks

I just stumbled across the following SQL 2005 code:

	BEGIN TRY
		UPDATE [tabProgramSite]
		SET
			[Name] = @ProgramSiteName
		WHERE [ProgramSiteID] = @ProgramSiteId
	END TRY
	BEGIN CATCH
	END CATCH

Nothing like catching an error… and doing nothing about it. I hope the user experience isn’t as robust.

Bookmark and Share

Popularity: 14% [?]

Related Posts

Society loses the value of objects unnecessarily destroyed.

-- Frédéric Bastiat, Economist

Comments 4

  1. Lucas wrote:

    Sounds familiar! I recently went through the source code of a production application adding (at least) some logging code into hundreds (well, maybe just dozens) of empty catches.

    It was VERY frustrating when the client reported a problem and sent us log files, and the logs didn’t have the slightest hint of what the problem was. Here we say the application “eats” the exceptions. om nom nom nom …

    The fact that it was written in VB was also frustrating, but that’s just me :)

    Posted 12 Jun 2008 at 2:47 pm
  2. brian wrote:

    VB… the language that should not be.

    Posted 12 Jun 2008 at 3:26 pm
  3. harborpirate wrote:

    Even worse is that in many cases you take a performance hit (though slight) for adding an exception handling routine. This is a great trade-off when you get a more robust application out of it since the difference is extremely small. When you have an empty catch you’re screwing yourself twice. Errors won’t bubble out to the calling software so you won’t know what happened AND your code will run ever so slightly slower.

    Posted 27 Jun 2008 at 5:10 pm
  4. brian wrote:

    Having a try/catch block without anything in the catch is like fishing and never looking at what’s on the hook.

    Posted 02 Jul 2008 at 9:43 am

Post a Comment

Your email is never published nor shared. Required fields are marked *