Skip to content

Commit 392a100

Browse files
authored
Merge pull request scala#7409 from hepin1989/2.13.x
=lib Add return type for Exception#handling
2 parents a2de25d + cee0b2b commit 392a100

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/library/scala/util/control/Exception.scala

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,19 @@ import scala.language.implicitConversions
154154
object Exception {
155155
type Catcher[+T] = PartialFunction[Throwable, T]
156156

157-
def mkCatcher[Ex <: Throwable: ClassTag, T](isDef: Ex => Boolean, f: Ex => T) = new Catcher[T] {
157+
def mkCatcher[Ex <: Throwable: ClassTag, T](isDef: Ex => Boolean, f: Ex => T): PartialFunction[Throwable, T] = new Catcher[T] {
158158
private def downcast(x: Throwable): Option[Ex] =
159159
if (classTag[Ex].runtimeClass.isAssignableFrom(x.getClass)) Some(x.asInstanceOf[Ex])
160160
else None
161161

162-
def isDefinedAt(x: Throwable) = downcast(x) exists isDef
162+
def isDefinedAt(x: Throwable): Boolean = downcast(x) exists isDef
163163
def apply(x: Throwable): T = f(downcast(x).get)
164164
}
165165

166-
def mkThrowableCatcher[T](isDef: Throwable => Boolean, f: Throwable => T) = mkCatcher[Throwable, T](isDef, f)
166+
def mkThrowableCatcher[T](isDef: Throwable => Boolean, f: Throwable => T): PartialFunction[Throwable, T] = mkCatcher[Throwable, T](isDef, f)
167167

168168
implicit def throwableSubtypeToCatcher[Ex <: Throwable: ClassTag, T](pf: PartialFunction[Ex, T]): Catcher[T] =
169-
mkCatcher(pf.isDefinedAt _, pf.apply _)
169+
mkCatcher(pf.isDefinedAt, pf.apply)
170170

171171
/** !!! Not at all sure of every factor which goes into this,
172172
* and/or whether we need multiple standard variations.
@@ -182,12 +182,12 @@ object Exception {
182182
trait Described {
183183
protected val name: String
184184
private[this] var _desc: String = ""
185-
def desc = _desc
185+
def desc: String = _desc
186186
def withDesc(s: String): this.type = {
187187
_desc = s
188188
this
189189
}
190-
override def toString() = name + "(" + desc + ")"
190+
override def toString(): String = name + "(" + desc + ")"
191191
}
192192

193193
/** A container class for finally code.
@@ -260,8 +260,8 @@ object Exception {
260260
* but with the supplied `apply` method replacing the current one. */
261261
def withApply[U](f: Throwable => U): Catch[U] = {
262262
val pf2 = new Catcher[U] {
263-
def isDefinedAt(x: Throwable) = pf isDefinedAt x
264-
def apply(x: Throwable) = f(x)
263+
def isDefinedAt(x: Throwable): Boolean = pf isDefinedAt x
264+
def apply(x: Throwable): U = f(x)
265265
}
266266
new Catch(pf2, fin, rethrow)
267267
}
@@ -344,10 +344,9 @@ object Exception {
344344
* }}}
345345
* @group dsl
346346
*/
347-
// TODO: Add return type
348-
def handling[T](exceptions: Class[_]*) = {
349-
def fun(f: Throwable => T) = catching(exceptions: _*) withApply f
350-
new By[Throwable => T, Catch[T]](fun _)
347+
def handling[T](exceptions: Class[_]*): By[Throwable => T, Catch[T]] = {
348+
def fun(f: Throwable => T): Catch[T] = catching(exceptions: _*) withApply f
349+
new By[Throwable => T, Catch[T]](fun)
351350
}
352351

353352
/** Returns a `Catch` object with no catch logic and the argument as the finally logic.

0 commit comments

Comments
 (0)