Skip to content

Commit

Permalink
Issue 12558 - Document implicit catch statement deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 committed Jul 10, 2016
1 parent 5e0915d commit 458ff50
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
27 changes: 27 additions & 0 deletions deprecate.dd
Expand Up @@ -14,6 +14,7 @@ $(SPEC_S Deprecated Features,
$(TROW $(DEPLINK delete), future,  ,  ,  )
$(TROW $(DEPLINK scope for allocating classes on the stack), future,  ,  ,  )
$(TROW $(DEPLINK Imaginary and complex types), future,  ,  ,  )
$(TROW $(DEPLINK Implicit catch statement), 2.072, 2.072, future, future )
$(TROW $(DEPLINK .sort and .reverse properties for arrays), ?, 2.072;,  ,  )
$(TROW $(DEPLINK C-style array pointers), ?, 2.072;,  ,  )
$(TROW $(DEPLINK Floating point NCEG operators), ?, 2.066, 2.072,  )
Expand Down Expand Up @@ -203,6 +204,32 @@ $(H4 Rationale)
)


$(H3 $(DEPNAME Implicit catch statement))
$(P One can catch everything by using $(D catch) without specifying a type.)
---
int[] arr = new int[](10);
// This will throw a RangeError
try { arr[42]++; }
catch { writeln("An error was caught and ignored"); }
---

$(H4 Corrective Action)
$(P Either don't catch `Throwable` or replace `catch {}` with `catch (Throwable) {}`)
---
int[] arr = new int[](10);
// This will throw a RangeError
try { arr[42]++; }
catch (Throwable) { writeln("An error was caught and ignored"); }
---

$(H4 Rationale)
$(P Catching `Throwable` should not be encouraged by the language,
because certain core guarantee cannot be satisfied, e.g. the stack might not get cleaned
up and destructors might not get run.
This change helps ensure catching `Throwable` is always a conscious and visible decision
on the programmer's side.
)


$(H3 $(DEPNAME .sort and .reverse properties for arrays))
$(P D arrays can be manipulated using these built-in properties.
Expand Down
4 changes: 0 additions & 4 deletions spec/grammar.dd
Expand Up @@ -779,13 +779,9 @@ $(GNAME TryStatement):
$(D try) $(PSSCOPE) $(GLINK FinallyStatement)

$(GNAME Catches):
$(GLINK LastCatch)
$(GLINK Catch)
$(GLINK Catch) $(I Catches)

$(GNAME LastCatch):
$(D catch) $(PS0)

$(GNAME Catch):
$(D catch $(LPAREN)) $(GLINK CatchParameter) $(D $(RPAREN)) $(PS0)

Expand Down

0 comments on commit 458ff50

Please sign in to comment.