How to print a message while handling errors using try, throw and catch

I want to print a message ("Working with the table does not exist in the database") in my query.

My request:

create proc sp_emprecord as begin select * from employe end begin try execute sp_emprecord end try begin catch select error_message() as errormessage, error_number() as erronumber, error_state() as errorstate, error_procedure() as errorprocedure, error_line() as errorline; end catch 
+4
source share
1 answer

Try the following:

 create proc sp_emprecord as begin select * from employe end go begin try execute sp_emprecord end try begin catch if(ERROR_NUMBER() = 208) RAISERROR ('The table employe is not exist in database', 0, 1) WITH NOWAIT; else select error_message() as errormessage, error_number() as erronumber, error_state() as errorstate, error_procedure() as errorprocedure, error_line() as errorline; end catch 
+8
source

Source: https://habr.com/ru/post/1432935/


All Articles