diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-09-15 15:39:12 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-10-10 13:25:32 +0200 |
commit | 66f7f7d23264374f9fbc581538fa1f47de16433c (patch) | |
tree | c6e1bcd90cf1fc79351d26c157bd8e768da140a9 /src/dotty | |
parent | e4a7db12c2e24b668f146c75469c1e61b7455456 (diff) | |
download | dotty-66f7f7d23264374f9fbc581538fa1f47de16433c.tar.gz dotty-66f7f7d23264374f9fbc581538fa1f47de16433c.tar.bz2 dotty-66f7f7d23264374f9fbc581538fa1f47de16433c.zip |
Use highlighting in explanation classes
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/reporting/Examples.scala | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/reporting/Examples.scala b/src/dotty/tools/dotc/reporting/Examples.scala index d2dbd70eb..9759d39e8 100644 --- a/src/dotty/tools/dotc/reporting/Examples.scala +++ b/src/dotty/tools/dotc/reporting/Examples.scala @@ -3,6 +3,7 @@ package dotc package reporting import dotc.core.Contexts.Context +import dotc.printing.SyntaxHighlighting._ object ErrorExplanations { import dotc.ast.Trees._ @@ -36,32 +37,40 @@ object ErrorExplanations { case Block(Nil, untpd.EmptyTree) => "{}" case _ => tryBody.show } - s"""|Explanation: - |============ - |A try expression should be followed by some mechanism to handle any exceptions - |thrown. Typically a `catch` expression follows the `try` and pattern matches - |on any expected exceptions. For example: - | - |try $tryString catch { - | case t: Throwable => ??? - |} - | - |It is also possible to follow a `try` immediately by a finally - letting the - |exception propagate - but still allowing for some clean up in `finally`: - | - |try $tryString finally { - | // perform your cleanup here! - |}""".stripMargin + + val code1 = + s"""|try $tryString catch { + | case t: Throwable => ??? + |}""".stripMargin + + val code2 = + s"""|try $tryString finally { + | // perform your cleanup here! + |}""".stripMargin + + hl"""|Explanation: + |============ + |A ${"try"} expression should be followed by some mechanism to handle any exceptions + |thrown. Typically a ${"catch"} expression follows the ${"try"} and pattern matches + |on any expected exceptions. For example: + | + |$code1 + | + |It is also possible to follow a ${"try"} immediately by a ${"finally"} - letting the + |exception propagate - but still allowing for some clean up in ${"finally"}: + | + |$code2 + """.stripMargin } } case class EmptyCatchBlock(tryBody: untpd.Tree)(implicit ctx: Context) extends EmptyCatchOrFinallyBlock(tryBody) { val msg = - "`catch` block does not contain a valid expression, try adding a case like - `case e: Exception =>` to the block" + hl"""The ${"catch"} block does not contain a valid expression, try adding a case like - `${"case e: Exception =>"}` to the block""" } case class EmptyCatchAndFinallyBlock(tryBody: untpd.Tree)(implicit ctx: Context) extends EmptyCatchOrFinallyBlock(tryBody) { val msg = - "A try without `catch` or `finally` is equivalent to putting its body in a block; no exceptions are handled." + hl"""A ${"try"} without ${"catch"} or ${"finally"} is equivalent to putting its body in a block; no exceptions are handled.""" } } |