Skip to content
This repository has been archived by the owner on Dec 31, 2019. It is now read-only.

try only #6

Closed
bradennapier opened this issue Sep 16, 2017 · 7 comments
Closed

try only #6

bradennapier opened this issue Sep 16, 2017 · 7 comments

Comments

@bradennapier
Copy link

bradennapier commented Sep 16, 2017

As far as I can tell, this is all about

try {
 ... code 
} catch {

}

but what about situations that we want to run some code and simply do not care about errors occurring at all?

try {
   ...code
}

or

try {
  ....code
} finally {
  ....code
}

I would think there are plenty of situations like that that occur.

My apologies if this is already implemented in some way that I am unaware of.

@bakkot
Copy link

bakkot commented Sep 17, 2017

try {
  ....code
} finally {
  ....code
}

is already legal. Moreover, it has the semantics of not swallowing the error, but rather propagating it; this establishes the precedent that omitting the catch propagates the error, a precedent I would not want try { ...code } to break.

(This precedent is also seen in languages where you can have conditional catch clauses: if you have some number of conditional catch clauses and an error matches none of them, it propagates.)

Edit, 2018-06-15: For posterity, I want to note that Julia supported try-without-catch and has since deprecated it for the reason given here.

@Mouvedia
Copy link

Mouvedia commented Dec 18, 2018

…that omitting the catch propagates the error, a precedent I would not want try { ...code } to break.

@bakkot @michaelficarra well then what about

try {
 ... code
} catch;

// instead of

try {
 ... code 
} catch {}

?

@ljharb
Copy link
Member

ljharb commented Dec 18, 2018

@Mouvedia this feature is already landed in ES2019; however, i suspect your suggestion would run into trouble with ASI. Additionally, how would you have multiple statements in a catch body that had no binding?

@Mouvedia
Copy link

Mouvedia commented Dec 18, 2018

this feature is already landed in ES2019

Good.

Additionally, how would you have multiple statements in a catch body that had no binding?

Sorry but, could you explain what you mean by "catch body that had no binding"?
@ljharb In my example the catch body is empty which means the brackets are useless.

@ljharb
Copy link
Member

ljharb commented Dec 18, 2018

@Mouvedia ah, are you asking if the { } can be omitted as well?

That seems like it'd be inconsistent with the rest of the language unless you could have an empty if, while, do, for, function body etc, all of which allowed omitting the curly braces.

@Mouvedia
Copy link

Mouvedia commented Dec 18, 2018

are you asking if the { } can be omitted as well?

Yes, I though my example was clear enough. My bad I should have been explicit.

That seems like it'd be inconsistent with the rest of the language unless you could have an empty if, while, do, for, function body etc, all of which allowed omitting the curly braces.

I don't think you can make a parallel for all of these. Only do/while could be considered somewhat similar.

do { /* … */ } while; could potentially be a shorthand for do { /* … */ } while (true); but I digress.
My point is they didn't go all the way: if the body is empty removing {} should have been the logical next step.

@ljharb
Copy link
Member

ljharb commented Dec 18, 2018

That sounds like a different proposal; I'd encourage you to write one up and email it to es-discuss :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants