diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-09-15 17:31:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-15 17:31:21 +0200 |
commit | 5d8f132b98ca10e47773275c7048ce132f5f197c (patch) | |
tree | 3dd3838ad2f969a10837d5c1b6ec2b229e0a0929 /src/dotty/tools | |
parent | 70a8426912f6f256536470a046cdf86827ab2c93 (diff) | |
parent | d1eeb5ffd9ee701f0ffce21eac10227328178113 (diff) | |
download | dotty-5d8f132b98ca10e47773275c7048ce132f5f197c.tar.gz dotty-5d8f132b98ca10e47773275c7048ce132f5f197c.tar.bz2 dotty-5d8f132b98ca10e47773275c7048ce132f5f197c.zip |
Merge pull request #1509 from felixmulder/topic/better-try-catch-messages
Better `try` and `catch` messages
Diffstat (limited to 'src/dotty/tools')
-rw-r--r-- | src/dotty/tools/dotc/parsing/Parsers.scala | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index 378aa6ed7..a06930058 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1009,9 +1009,23 @@ object Parsers { in.nextToken() expr() } else EmptyTree + + handler match { + case Block(Nil, EmptyTree) => syntaxError( + "`catch` block does not contain a valid expression, try adding a case like - `case e: Exception =>` to the block", + handler.pos + ) + case _ => + } + val finalizer = - if (handler.isEmpty || in.token == FINALLY) { accept(FINALLY); expr() } - else EmptyTree + if (in.token == FINALLY) { accept(FINALLY); expr() } + else { + if (handler.isEmpty) + warning("A try without `catch` or `finally` is equivalent to putting its body in a block; no exceptions are handled.") + + EmptyTree + } ParsedTry(body, handler, finalizer) } case THROW => |