Apparently SQL 2005 has a TRY/CATCH construct.
SQL 2000
VB Code:
Use Funds
Go
Select * from Funds_T Where ConfItem='AMC'
Go
Insert into Funds_T Values (null,null)
Go
.
. returns in the Message pane
.
ConfItem ConfData
-------------------------------------------------- --------------------------------------------------
AMC 4.9.4
(1 row(s) affected)
Server: Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'ConfItem', table 'Funds.dbo.Funds_T';
column does not allow nulls. INSERT fails.
The statement has been terminated.
Blows up because we don't allow NULL values in the columns of this table...
SQL 2005
VB Code:
Use Funds
Go
Select * from Funds_T Where ConfItem='AMC'
Go
Begin Try
Insert into Funds_T Values (null,null)
End Try
Begin Catch
Select 'Insert did not work!'
End Catch
Go
.
. returns
.
ConfItem ConfData
-------------------------------------------------- --------------------------------------------------
AMC 4.8.4
(1 row(s) affected)
(0 row(s) affected)
--------------------
Insert did not work!
(1 row(s) affected)
The books online has a nice example of an error function - check this out
VB Code:
Use Funds
Go
CREATE PROCEDURE usp_GetErrorInfo
AS
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
GO
Select * from Funds_T Where ConfItem='AMC'
Go
Begin Try
Insert into Funds_T Values (null,null)
End Try
Begin Catch
exec usp_GetErrorInfo
End Catch
Go
.
. returns...
.
ConfItem ConfData
-------------------------------------------------- --------------------------------------------------
AMC 4.8.4
(1 row(s) affected)
(0 row(s) affected)
ErrorNumber
ErrorSeverity
ErrorState
ErrorProcedure
ErrorLine
ErrorMessage
515
16
2
NULL
2
Cannot insert the value NULL into column 'ConfItem', table 'Funds.dbo.Funds_T';
column does not allow nulls. INSERT fails.
(1 row(s) affected)
I had to cut up the results so it would post properly - but you get the idea!