Skip to content

Conversation

DanielRosenwasser
Copy link
Member

try-less catch Blocks

If the parser now sees

catch (x) {
}

or

catch (x) {
}
finally {
}

the user will be issued the message

A 'catch' clause must be preceded by a 'try' statement.

'try' expected.


try-less finally Blocks

If the parser now sees

finally { }

the user will be issued the message

A 'finally' block must be preceded by a 'try' statement.

'try' expected.


Fixes #216.

…ry' block.

Fixes #216.

As a note of this fix, when a 'catch' block is followed by a 'finally' block, only the 'catch' keyword gets an error reported on it.
@DanielRosenwasser DanielRosenwasser changed the title Tryless catches finally parse nicely Tryless catches finally parse nicely Jul 26, 2014
@DanielRosenwasser DanielRosenwasser changed the title Tryless catches finally parse nicely Improved errors for 'catch'/'finally' blocks missing 'try' statements Jul 26, 2014
@@ -160,6 +160,8 @@ module ts {
Constructor_implementation_expected: { code: 2240, category: DiagnosticCategory.Error, key: "Constructor implementation expected." },
An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2245, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." },
A_parameter_property_is_only_allowed_in_a_constructor_implementation: { code: 2246, category: DiagnosticCategory.Error, key: "A parameter property is only allowed in a constructor implementation." },
A_catch_clause_must_be_preceded_by_a_try_statement: { code: 2249, category: DiagnosticCategory.Error, key: "A 'catch' clause must be preceded by a 'try' statement." },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these seem unnecessary. you can just call parseTryStatement and you'll get the perfectly good error "'try' expected"

@mhegazy
Copy link
Contributor

mhegazy commented Aug 4, 2014

👍

DanielRosenwasser added a commit that referenced this pull request Aug 4, 2014
Improved errors for 'catch'/'finally' blocks missing 'try' statements
@DanielRosenwasser DanielRosenwasser merged commit 40f6ed0 into master Aug 4, 2014
@DanielRosenwasser DanielRosenwasser deleted the trylessCatchesFinallyParseNicely branch August 4, 2014 22:56
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better error message for 'catch' block missing 'try'.
4 participants