Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6957189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:58:04+00:00 2026-05-27T14:58:04+00:00

I am using a try-catch block in T-SQL, and I want to only catch

  • 0

I am using a try-catch block in T-SQL, and I want to only catch a specific error number. In other cases, I am using RAISERROR() as a poor-man’s re-throw to return error information to the application.

When I try the following, I get an “Incorrect syntax near ‘error_message'” error:

raiserror
    (
         error_message()
        ,1
        ,1
    )

The following, however, works fine:

declare @err varchar(100)
set @err = error_message()

raiserror
    (
         @err
        ,1
        ,1
    )

I thought it might be a typecasting quirk, so I tried this, but that also yielded a syntax error:

raiserror
    (
         cast(error_message() as varchar(100))
        ,1
        ,1
    )

What’s going on here? Why do I have to store the result of ERROR_MESSAGE() in a variable before using it as a parameter to RAISERROR(), instead of calling the function directly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:58:04+00:00Added an answer on May 27, 2026 at 2:58 pm

    Below post answers your Question: https://stackoverflow.com/a/3415125/639960

    In a nutshell (quoted from above post):

    RAISERROR follows the same rules as any other stored procedure call.
    Parameters passed in must be a constant or a variable. You cannot pass
    a function directly as a parameter.

    See Executing Stored Procedures for documentation on this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is a decent way to handle PDO error when using try catch block?
I am writing a stored procedure where i m using try catch block. Now
I was just wondering which would be cheaper, using a try catch block for
I am currently using two catch blocks after a try block. The first catches
We are using SQL 2005 and the try-catch functionality to handle all of our
In cases when you use a try catch block as such. try { //Do
I'm using a try-catch block in the following Actionscript 3 code: try { this._subtitle
I am using a try catch block to catch an exception. The console shows
Is there any overhead in Java for using a try/catch block, as opposed to
How to log the JavaScript exceptions? Yes I am using Try catch() block in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.