SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 TRY CATCH block.
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Hariarul
Posting Yak Master

India
160 Posts

Posted - 09/18/2006 :  02:02:42  Show Profile
Hi,

Is it a good practice to use TRY - CATCH block in all the stored procedures even it does a simple query / manipulation ?

Thanks,

HHA


harsh_athalye
Flowing Fount of Yak Knowledge

India
5581 Posts

Posted - 09/18/2006 :  02:07:16  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message
It's always better to be prepared for the worst...Even though it is a simple query, things may go wrong. In such circumstances, handling errors gracefully is always good and make your application more robust and reliable.

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

chiragkhabaria
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 09/18/2006 :  03:18:32  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message
http://www.sqlservercentral.com/columnists/rVasant/exceptionhandlinginsqlserver2005.asp

Chirag
Go to Top of Page

Hariarul
Posting Yak Master

India
160 Posts

Posted - 09/19/2006 :  06:25:53  Show Profile
Thanks !!
Go to Top of Page

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 09/19/2006 :  08:15:15  Show Profile  Visit nr's Homepage
What would you do with the error?

I tend to use it in control SPs.
If you are just calling an SP and are just going to re-raise any error then there doesn't seem to be much point.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Hariarul
Posting Yak Master

India
160 Posts

Posted - 09/22/2006 :  05:58:39  Show Profile
Throw it to the application layer
Go to Top of Page

mr_mist
Grunnio

United Kingdom
1870 Posts

Posted - 09/22/2006 :  08:43:14  Show Profile  Visit mr_mist's Homepage
quote:
Originally posted by Hariarul

Throw it to the application layer



Well SQL Server would do that anyway, so there's not much point unless you are either going to alter the error message somehow, or otherwise do some activity that would not take place were it not for the CATCH block.

-------
Moo. :)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 09/22/2006 :  09:43:01  Show Profile
Really? Are you guys saying that you wouldn't handle all errors and just let SQL Server raise out?

Is that right?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

mr_mist
Grunnio

United Kingdom
1870 Posts

Posted - 09/22/2006 :  10:14:01  Show Profile  Visit mr_mist's Homepage
quote:
Originally posted by X002548

Really? Are you guys saying that you wouldn't handle all errors and just let SQL Server raise out?




That's not what I said. Can't speak for the other people.

I said that if all the OP was going to do in the CATCH block is re-raise the original error, there's no point in the CATCH block.

Personally, I'd write some code in the CATCH block that either fixed the issue, or did some other kind of error logging / reporting.

-------
Moo. :)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000