Results 1 to 7 of 7

Thread: Try...catch

  1. #1
    Join Date
    Jan 2008
    Posts
    186

    Unanswered: Try...catch

    Okay, so why does this stmt fail inside a catch block?
    Code:
    RAISERROR( ERROR_MESSAGE(), ERROR_SEVERITY(), ERROR_STATE() )
    The message I get is:
    Code:
    Incorrect syntax near 'ERROR_MESSAGE'.
    Now if I replace that line with something like
    Code:
    RAISERROR( 'some msg', 15, 1 )
    Then it works fine

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Dunno why but it does. My template includes whacking those function values into variables. To quote Rainier Wolfcastle: "No biggie"
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    apparently you have to put the contents of ERROR_MESSAGE() in a variable which you can then pass to RAISERROR. lame.

    search for usp_RethrowError here: http://technet.microsoft.com/en-us/l.../ms179296.aspx

  4. #4
    Join Date
    Jan 2008
    Posts
    186
    Okay so I'm using this sort of set up
    Code:
    BEGIN TRAN
    
    BEGIN TRY
    ...
    END TRY
    BEGIN CATCH
    IF @@TRANCOUNT > 0 
    	BEGIN
    		ROLLBACK TRANSACTION
    		EXEC usp_throwError // as per Jezemine's post
    	END
    END CATCH
    
    IF @@TRANCOUNT > 0
    	COMMIT TRANSACTION
    Does that look alright?

  5. #5
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    the // will give you a syntax error


  6. #6
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Quote Originally Posted by dbguyfh
    Okay, so why does this stmt fail inside a catch block?
    Code:
    RAISERROR( ERROR_MESSAGE(), ERROR_SEVERITY(), ERROR_STATE() )
    The message I get is:
    Code:
    Incorrect syntax near 'ERROR_MESSAGE'.
    Now if I replace that line with something like
    Code:
    RAISERROR( 'some msg', 15, 1 )
    Then it works fine
    RAISERROR follows the same rules as a procedure call in TSQL. e.g., you can't pass a getdate() as a parameter to a stored procedure.
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  7. #7
    Join Date
    Jan 2008
    Posts
    186
    Yeah... Figured that. I just assign them to variables within that usp_throwError routine.

    All seems to work well now

    Thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •