Вот несколько примеров:
компилятор / Scala / инструменты / NSC / переводчик / InteractiveReader.scala
def readLine(prompt: String): String = {
def handler: Catcher[String] = {
case e: IOException if restartSystemCall(e) => readLine(prompt)
}
catching(handler) { readOneLine(prompt) }
}
компилятор / Scala / инструменты / NSC / Interpreter.scala
/** We turn off the binding to accomodate ticket #2817 */
def onErr: Catcher[(String, Boolean)] = {
case t: Throwable if bindLastException =>
withoutBindingLastException {
quietBind("lastException", "java.lang.Throwable", t)
(stringFromWriter(t.printStackTrace(_)), false)
}
}
catching(onErr) {
unwrapping(wrapperExceptions: _*) {
(resultValMethod.invoke(loadedResultObject).toString, true)
}
}
...
/** Temporarily be quiet */
def beQuietDuring[T](operation: => T): T = {
val wasPrinting = printResults
ultimately(printResults = wasPrinting) {
printResults = false
operation
}
}
/** whether to bind the lastException variable */
private var bindLastException = true
/** Temporarily stop binding lastException */
def withoutBindingLastException[T](operation: => T): T = {
val wasBinding = bindLastException
ultimately(bindLastException = wasBinding) {
bindLastException = false
operation
}
}
компилятор / Scala / инструменты / NSC / И.О. / Process.scala
def exitValue(): Option[Int] =
catching(classOf[IllegalThreadStateException]) opt process.exitValue()
библиотека / Scala / XML / включить / саксофон / Main.scala
def saxe[T](body: => T) = catching[T](classOf[SAXException]) opt body
...
ignoring(classOf[SAXException]) {
includer.setProperty(lexicalHandler, s)
s setFilter includer
}