Author |
Topic |
Hariarul
Posting Yak Master
160 Posts |
Posted - 2006-09-18 : 02:02:42
|
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
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-09-18 : 02:07:16
|
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 AthalyeIndia."Nothing is Impossible" |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-09-18 : 03:18:32
|
http://www.sqlservercentral.com/columnists/rVasant/exceptionhandlinginsqlserver2005.aspChirag |
|
|
Hariarul
Posting Yak Master
160 Posts |
Posted - 2006-09-19 : 06:25:53
|
Thanks !! |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-09-19 : 08:15:15
|
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. |
|
|
Hariarul
Posting Yak Master
160 Posts |
Posted - 2006-09-22 : 05:58:39
|
Throw it to the application layer |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2006-09-22 : 08:43:14
|
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. :) |
|
|
X002548
Not Just a Number
15586 Posts |
|
mr_mist
Grunnio
1870 Posts |
Posted - 2006-09-22 : 10:14:01
|
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. :) |
|
|
|