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 439405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:46:21+00:00 2026-05-12T20:46:21+00:00

The title really is the question for this one: Is there an equivalent in

  • 0

The title really is the question for this one: Is there an equivalent in T-SQL to C#’s “throw;” to re-throw exceptions?

In C# one can do this:

try
{
    DoSomethingThatMightThrowAnException();
}
catch (Exception ex)
{
    // Do something with the exception
    throw; // Re-throw it as-is.
}

Is there something in T-SQL’s BEGIN CATCH functionality that does the same?

  • 1 1 Answer
  • 1 View
  • 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-12T20:46:21+00:00Added an answer on May 12, 2026 at 8:46 pm

    You can use RAISERROR. From the MSDN documentation on RAISERROR:

    BEGIN TRY
        -- RAISERROR with severity 11-19 will cause execution to 
        -- jump to the CATCH block
        RAISERROR ('Error raised in TRY block.', -- Message text.
                   16, -- Severity.
                   1 -- State.
                   );
    END TRY
    BEGIN CATCH
        DECLARE @ErrorMessage NVARCHAR(4000);
        DECLARE @ErrorSeverity INT;
        DECLARE @ErrorState INT;
    
        SELECT @ErrorMessage = ERROR_MESSAGE(),
               @ErrorSeverity = ERROR_SEVERITY(),
               @ErrorState = ERROR_STATE();
    
        -- Use RAISERROR inside the CATCH block to return 
        -- error information about the original error that 
        -- caused execution to jump to the CATCH block.
        RAISERROR (@ErrorMessage, -- Message text.
                   @ErrorSeverity, -- Severity.
                   @ErrorState -- State.
                   );
    END CATCH;
    

    EDIT:

    This is not really the same thing as c#’s throw or throw ex. As @henrikstaunpoulsen points out you don’t get the original error number in the new error (RAISERROR is restricted in which numbers it can use). You would have to use some sort of convention and parse the information (if available) out of the message.

    MSDN has an article Using TRY…CATCH in Transact-SQL and I used some of the code to create the test below:

    use test;
    GO
    
    IF OBJECT_ID (N'usp_RethrowError',N'P') IS NOT NULL
        DROP PROCEDURE usp_RethrowError;
    GO
    
    CREATE PROCEDURE usp_RethrowError AS
        IF ERROR_NUMBER() IS NULL
            RETURN;
    
        DECLARE 
            @ErrorMessage    NVARCHAR(4000),
            @ErrorNumber     INT,
            @ErrorSeverity   INT,
            @ErrorState      INT,
            @ErrorLine       INT,
            @ErrorProcedure  NVARCHAR(200);
    
        SELECT 
            @ErrorNumber = ERROR_NUMBER(),
            @ErrorSeverity = ERROR_SEVERITY(),
            @ErrorState = ERROR_STATE(),
            @ErrorLine = ERROR_LINE(),
            @ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-');
    
        SELECT @ErrorMessage = 
            N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' + 
                'Message: '+ ERROR_MESSAGE();
    
        RAISERROR 
            (
            @ErrorMessage, 
            @ErrorSeverity, 
            @ErrorState,               
            @ErrorNumber,    -- parameter: original error number.
            @ErrorSeverity,  -- parameter: original error severity.
            @ErrorState,     -- parameter: original error state.
            @ErrorProcedure, -- parameter: original error procedure name.
            @ErrorLine       -- parameter: original error line number.
            );
    GO
    
    PRINT 'No Catch'
    DROP TABLE XXXX
    
    PRINT 'Single Catch'
    BEGIN TRY
        DROP TABLE XXXX
    END TRY
    BEGIN CATCH
        EXEC usp_RethrowError;
    END CATCH;
    
    PRINT 'Double Catch'
    BEGIN TRY
        BEGIN TRY
            DROP TABLE XXXX
        END TRY
        BEGIN CATCH
            EXEC usp_RethrowError;
        END CATCH;
    END TRY
    BEGIN CATCH
        EXEC usp_RethrowError;
    END CATCH;
    

    Which produces the following output:

    No Catch
    Msg 3701, Level 11, State 5, Line 3
    Cannot drop the table 'XXXX', because it does not exist or you do not have permission.
    Single Catch
    Msg 50000, Level 11, State 5, Procedure usp_RethrowError, Line 25
    Error 3701, Level 11, State 5, Procedure -, Line 7, Message: Cannot drop the table 'XXXX', because it does not exist or you do not have permission.
    Double Catch
    Msg 50000, Level 11, State 5, Procedure usp_RethrowError, Line 25
    Error 50000, Level 11, State 5, Procedure usp_RethrowError, Line 25, Message: Error 3701, Level 11, State 5, Procedure -, Line 16, Message: Cannot drop the table 'XXXX', because it does not exist or you do not have permission.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Really strugging to title this question, so if anyone has suggestions feel free.) Say
i didn't really know how to title this question, but here's a thing that
I've searched for at question like this and i dont think there are one.
the question's in the title really. I have an online form where, after a
The question is in the title. It should be silly. But... I really don't
library(ggplot2) my_title = This is a really long title of a plot that I
The title really says it all: what is the difference between minus one and
Disclaimer This question is a repost. I originally asked it here . While there
Side note: I really could not think of a good title for this. Ok,
As the title suggests really. WriteData will be called for each split CSV item

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.