Raiserror not worked

Lora 200 Reputation points
2024-01-30T08:56:33.8966667+00:00

Why the raiserror not worked within begin try? Here is the code:

BEGIN TRY
    --Check 
    RAISERROR ('Error! Please retry', 10, 2)
    --If no errors 
    PRINT 'Successful'
END TRY
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,492 questions
{count} votes

Accepted answer
  1. LiHongMSFT-4306 31,081 Reputation points
    2024-01-30T09:05:04.73+00:00

    Hi @Lora Have you checked if the severity level issue? How about change the severity level to >10? See: RAISERROR

    Best regards, Cosmog Hong

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 119.7K Reputation points MVP
    2024-01-30T22:30:30.02+00:00

    You have specified the severity as 10, which only generates an informational messages (and for some reason results in severity level 0, which is the same as PRINT.)

    Specify the severity level as 16, which is the highest level for user errors.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.