March 3, 2008 at 10:27 pm
Hi
I need to know the actual functioning of "@@Error"
Also i need to know about the try/catch with examples.
Can anyone help me.
March 4, 2008 at 3:39 am
BEGIN TRAN
DECLARE @intErrorCode INT
--Some code
/* check to see if we had an error and if so goto the error handler and rollback the transaction */
SELECT @intErrorCode = @@ERROR
IF ( @intErrorCode <> 0) GOTO PROBLEM
--some more code
/* check to see if we had an error and if so goto the error handler and rollback the transaction */
SELECT @intErrorCode = @@ERROR
IF ( @intErrorCode <> 0) GOTO PROBLEM
/* commit the transaction because no errors were raised during execution */
COMMIT TRAN
/* if we had an error code raised during execution */
PROBLEM:
/* if an error was raised */
IF ( @intErrorCode <> 0)
BEGIN
/* rollback the transaction */
ROLLBACK TRAN
END
March 4, 2008 at 4:38 am
there must be an art at SSC
but I found this one in my examples http://www.simple-talk.com/sql/t-sql-programming/sql-server-error-handling-workbench
BEGIN TRY
SELECT CONVERT(INT, 'XYZ')
END TRY
BEGIN CATCH
-- ERROR_ stuff only available immediatly after catch !!
PRINT ERROR_MESSAGE()
PRINT ERROR_NUMBER()
PRINT ERROR_SEVERITY()
END CATCH
GO
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 4, 2008 at 6:04 am
I was just going to post the exact same link. Cool!
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
March 4, 2008 at 7:24 am
I knew your name did ring a bell 😀
the SSC-article http://www.sqlservercentral.com/articles/News/exceptionhandlinginsqlserver2005/2237/
introduces try-catch.
but I got to admit I like your art. more because it goes more in detail and has a bigger scope. :w00t:
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 4, 2008 at 10:00 pm
Thank You Sir
Thanks alot.
June 18, 2008 at 9:10 am
June 18, 2008 at 9:21 am
A log file is a mechanism I'd only use from the application side. If you're capturing error information inside SQL Server, just write it out to a table.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
June 18, 2008 at 9:33 am
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply