View Single Post

   
  #4 (permalink)  
Old 02-29-2008, 03:56 AM
Erland Sommarskog
 
Posts: n/a
Default Re: How to catch an exception?

Evgeny Gopengauz (evgop@ucs.ru) writes:
> Is there something like exception handling in T-SQL?
> For example, how to catch an error of convertion at this
> sample:
>
> CREATE PROCEDURE SP
> @param VARCHAR(50)
> AS BEGIN
> DELCARE @var INT
> -- try {
> SET @var = CONVERT( int, @param)
> -- } catch (error#245) {
> -- handle an error right here
> -- }
> END
>
> It must be invisible for a caller of SP if something wrong inside SP.


For SQL2000 the answer is very distinctively: NO. Error handling in
SQL Server 2000 is a mess. There are two articles on my web site about
the topic http://www.sommarskog.se/error-handling-I.html and
http://www.sommarskog.se/error-handling-II.html.

The good news is that in the next version of SQL Server, SQL 2005 which
now is in beta, there are great improvements in this area, and there
is indeed a TRY-CATCH construct.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Reply With Quote