Wednesday, March 7, 2012

Cannot Trap Specific Errors

I set up the following code to trap errors after each SQL command issued. I
n
the Error_Handler section, I populate an error table which gets exported to
Microsoft Access. Up until now it has been working, however, I got an error
:
"There is already an object named 'TempCalc010' in the database", which
stopped the program immediately and did not populate the error file. Is
there anyway to trap this error and populate the error file ?
Set @.iErr = @.@.Error
If @.iErr <> 0
Begin
Set @.vErrMess = '#50 Cannot update LSDC for TC FTF.'
GoTo Error_Handler
EndImplementing Error Handling with Stored Procedures
http://www.sommarskog.se/error-handling-II.html
Error Handling in SQL Server – a Background
http://www.sommarskog.se/error-handling-I.html
AMB
"rmcompute" wrote:

> I set up the following code to trap errors after each SQL command issued.
In
> the Error_Handler section, I populate an error table which gets exported t
o
> Microsoft Access. Up until now it has been working, however, I got an err
or:
> "There is already an object named 'TempCalc010' in the database", which
> stopped the program immediately and did not populate the error file. Is
> there anyway to trap this error and populate the error file ?
> Set @.iErr = @.@.Error
> If @.iErr <> 0
> Begin
> Set @.vErrMess = '#50 Cannot update LSDC for TC FTF.'
> GoTo Error_Handler
> End
>|||What is the code in the Error_Handler?
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"rmcompute" <rmcompute@.discussions.microsoft.com> wrote in message
news:3F35FF3B-175C-4F4A-8E4D-DF9CD01D1429@.microsoft.com...
>I set up the following code to trap errors after each SQL command issued.
>In
> the Error_Handler section, I populate an error table which gets exported
> to
> Microsoft Access. Up until now it has been working, however, I got an
> error:
> "There is already an object named 'TempCalc010' in the database", which
> stopped the program immediately and did not populate the error file. Is
> there anyway to trap this error and populate the error file ?
> Set @.iErr = @.@.Error
> If @.iErr <> 0
> Begin
> Set @.vErrMess = '#50 Cannot update LSDC for TC FTF.'
> GoTo Error_Handler
> End
>|||Exit_Procedure:
Return @.iErr
Error_Handler:
SELECT @.vErrDesc = description
FROM master.dbo.sysmessages
WHERE error = @.iErr
Set @.vErrNumMess = 'Sys #:' + RTrim(Cast(@.iErr as nvarchar(10))) + ' Sys
Desc:' +
RTrim(@.vErrDesc) + ' Prog Desc:' + RTrim(@.vErrMess)
Insert
SvcReports.dbo. tblSRProcessErrors(SysRec,Program,ErrorC
ode,SysDesc,ProgDesc)
Values('B','u_spSRCreateActualData',@.iEr
r,@.vErrDesc,@.vErrMess)
Raiserror(@.vErrNumMess,16,1,5) With Log
Goto Exit_Procedure
Go
"Arnie Rowland" wrote:

> What is the code in the Error_Handler?
> --
> Arnie Rowland, YACE*
> "To be successful, your heart must accompany your knowledge."
> *Yet Another certification Exam
>
> "rmcompute" <rmcompute@.discussions.microsoft.com> wrote in message
> news:3F35FF3B-175C-4F4A-8E4D-DF9CD01D1429@.microsoft.com...
>
>|||Where is TempCalc010 created/used/accessed?
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"rmcompute" <rmcompute@.discussions.microsoft.com> wrote in message
news:513BE8FE-5592-45AF-B4F8-4506E67A7909@.microsoft.com...
> Exit_Procedure:
> Return @.iErr
> Error_Handler:
> SELECT @.vErrDesc = description
> FROM master.dbo.sysmessages
> WHERE error = @.iErr
> Set @.vErrNumMess = 'Sys #:' + RTrim(Cast(@.iErr as nvarchar(10))) + '
> Sys
> Desc:' +
> RTrim(@.vErrDesc) + ' Prog Desc:' + RTrim(@.vErrMess)
> Insert
> SvcReports.dbo. tblSRProcessErrors(SysRec,Program,ErrorC
ode,SysDesc,ProgDes
c)
> Values('B','u_spSRCreateActualData',@.iEr
r,@.vErrDesc,@.vErrMess)
> Raiserror(@.vErrNumMess,16,1,5) With Log
> Goto Exit_Procedure
> Go
> "Arnie Rowland" wrote:
>|||It exists in the first part of the program:
SELECT Fielda, Fieldb, Fieldc ...
INTO TempCalc010
From TempCalc005
I can prevent this error by checking if the file exists and then deleting
it before
running this step, but my question was, are there certain errors that
@.@.Error
does not catch and if so, how are those errors trapped ?
"Arnie Rowland" wrote:

> Where is TempCalc010 created/used/accessed?
> --
> Arnie Rowland, YACE*
> "To be successful, your heart must accompany your knowledge."
> *Yet Another certification Exam
>
> "rmcompute" <rmcompute@.discussions.microsoft.com> wrote in message
> news:513BE8FE-5592-45AF-B4F8-4506E67A7909@.microsoft.com...
>
>|||Yes, there are certain errors that cause an procedrue 'abort', and any error
handling code will be missed. For a better analysis of the issues, Refer
back to the articles taht Alejandro offered.
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"rmcompute" <rmcompute@.discussions.microsoft.com> wrote in message
news:1E0C0080-6A0C-4BEB-8071-47F56FEED9E8@.microsoft.com...
> It exists in the first part of the program:
> SELECT Fielda, Fieldb, Fieldc ...
> INTO TempCalc010
> From TempCalc005
> I can prevent this error by checking if the file exists and then deleting
> it before
> running this step, but my question was, are there certain errors that
> @.@.Error
> does not catch and if so, how are those errors trapped ?
>
> "Arnie Rowland" wrote:
>|||Thank you.
"Alejandro Mesa" wrote:
> Implementing Error Handling with Stored Procedures
> http://www.sommarskog.se/error-handling-II.html
> Error Handling in SQL Server – a Background
> http://www.sommarskog.se/error-handling-I.html
>
> AMB
> "rmcompute" wrote:
>|||Ok. Thank you.
"Arnie Rowland" wrote:

> Yes, there are certain errors that cause an procedrue 'abort', and any err
or
> handling code will be missed. For a better analysis of the issues, Refer
> back to the articles taht Alejandro offered.
> --
> Arnie Rowland, YACE*
> "To be successful, your heart must accompany your knowledge."
> *Yet Another certification Exam
>
> "rmcompute" <rmcompute@.discussions.microsoft.com> wrote in message
> news:1E0C0080-6A0C-4BEB-8071-47F56FEED9E8@.microsoft.com...
>
>

No comments:

Post a Comment