Search

MSFT-MSO: END TRY throws an error if terminated with a semicolon by Narayan_Iyer

Closed
as Won't Fix Help for as Won't Fix

4
0
Sign in
to vote
Type: Bug
ID: 498085
Opened: 10/16/2009 4:35:24 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
END TRY throws error if it's ended with a semicolon. However, BEGIN TRY, BEGIN CATCH and END CATCH statements appear to happy to have terminated with a semicolon.

I have given the failing script in the repro steps section.

Please have a look.
Details (expand)
Product Language
English

Version

SQL Server 2008 R2 August CTP

Category

SQL Engine

Operating System

Win2003 Enterprise Server (SP2)
Operating System Language
US English
Steps to Reproduce
BEGIN TRY; -- No issues
SELECT 1;
END TRY; -- Fails

BEGIN CATCH; -- No issues
SELECT 2;
END CATCH; -- No issues

-- Look at the statement that is commented with "--Fails" above. That is the only statement in the script that fails if terminated with a semicolon.

Please have a look.
Actual Results
END TRY throws an error if terminated with a semicolon.
Expected Results
Should not throw error if terminated with a semicolon.

The following script should run fine.

BEGIN TRY; -- No issues
SELECT 1;
END TRY; -- Fails

BEGIN CATCH; -- No issues
SELECT 2;
END CATCH; -- No issues

Platform

X64
File Attachments
0 attachments
Sign in to post a comment.
Posted by aaronbertrand on 2/16/2010 at 11:30 PM
If that is the case then why not disallow semi-colons after all four statements? The story and the implementation seem to clash and leave a very unfinished and sloppy feel.
Posted by Microsoft on 12/29/2009 at 12:11 PM
I am resolving the corresonding SQL11 bug as "by design". Here is the explanation:

The semicolon between END TRY and BEGIN CATCH should not be allowed, because they are actually not different statements, but parts of the same TRY-CATCH statement. We only allow semicolons when they separate two statements in a sequence.

A word of explanation why then we allow semicolons after BEGIN TRY and BEGIN CATCH. These keywords serve as opening "parentheses" that start an embedded statement sequence. Semicolons after BEGIN TRY/BEGIN CATCH get parsed as part of that embedded sequence, with the first statement in the sequence being empty. While we allow this syntax, I would not recommend it as a good coding practice because it creates a wrong impression of BEGIN TRY/BEGIN CATCH being independent, standalone statements.
Posted by Microsoft on 10/19/2009 at 6:08 PM
This is a known quirk in the parser. We will take a look at fixing it for SQL 11. I am resolving the SQL 2008 R2 bug as won't fix.
Sign in to post a workaround.