Table of SQL Errors & Stored Procedures

I have this bit of code I found on the web at the end of each of my stored procedures:

ROLLBACK TRANSACTION

    	 PRINT '-----START: ERROR DETAILS-----'
    	 PRINT ERROR_NUMBER()
    	 PRINT ERROR_SEVERITY()
    	 PRINT ERROR_STATE()
    	 PRINT ERROR_PROCEDURE()
    	 PRINT ERROR_LINE()
    	 PRINT ERROR_MESSAGE()
    	 PRINT '-----END: ERROR DETAILS-----'

    		DECLARE @prmErrmsg NVARCHAR(4000);
    		DECLARE @prmErrSvr INT;

    		SELECT @prmErrmsg = ERROR_MESSAGE()
    			,@prmErrSvr = ERROR_SEVERITY();

    		INSERT INTO dbo.myErrors
    					([ErrorMessage]
    					,[ErrorSeverity]
    					,[DateCreated])
    			 VALUES
    					(@prmErrmsg
    					,@prmErrSvr
    					,GetutcDate())


    		RAISERROR(@prmErrmsg,@prmErrSvr,1)

It's writing entries to the myErrors table, but it's not writing an error message or an error severity.

My first question is why?

I believe it's got something to with the error severity being within a certain range.

How can I tell it to log verbose error messages ALWAYS, regardless of severity?

Answers


According to MSDN, ERROR_MESSAGE() etc are only set within the CATCH block of a TRY ... CATCH statement.


Need Your Help

JSON data from URL

ruby-on-rails json highcharts ruby-on-rails-3.2

I'm using Highcharts to display other graphs from csv's in my application, but now I have to access JSON data from a url (test.com/data/data1,temp) and i'm not sure how to best tackle this scenario...

lldb/Xcode: how to print thread index, id or name?

c++ objective-c xcode lldb

Problem: I want to trace a program with the help of breakpoints with action in Xcode, so what I am interested in is if my function is always executed in one thread.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.