@@ -154,19 +154,19 @@ import scala.language.implicitConversions
154
154
object Exception {
155
155
type Catcher [+ T ] = PartialFunction [Throwable , T ]
156
156
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 ] {
158
158
private def downcast (x : Throwable ): Option [Ex ] =
159
159
if (classTag[Ex ].runtimeClass.isAssignableFrom(x.getClass)) Some (x.asInstanceOf [Ex ])
160
160
else None
161
161
162
- def isDefinedAt (x : Throwable ) = downcast(x) exists isDef
162
+ def isDefinedAt (x : Throwable ): Boolean = downcast(x) exists isDef
163
163
def apply (x : Throwable ): T = f(downcast(x).get)
164
164
}
165
165
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)
167
167
168
168
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)
170
170
171
171
/** !!! Not at all sure of every factor which goes into this,
172
172
* and/or whether we need multiple standard variations.
@@ -182,12 +182,12 @@ object Exception {
182
182
trait Described {
183
183
protected val name : String
184
184
private [this ] var _desc : String = " "
185
- def desc = _desc
185
+ def desc : String = _desc
186
186
def withDesc (s : String ): this .type = {
187
187
_desc = s
188
188
this
189
189
}
190
- override def toString () = name + " (" + desc + " )"
190
+ override def toString (): String = name + " (" + desc + " )"
191
191
}
192
192
193
193
/** A container class for finally code.
@@ -260,8 +260,8 @@ object Exception {
260
260
* but with the supplied `apply` method replacing the current one. */
261
261
def withApply [U ](f : Throwable => U ): Catch [U ] = {
262
262
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)
265
265
}
266
266
new Catch (pf2, fin, rethrow)
267
267
}
@@ -344,10 +344,9 @@ object Exception {
344
344
* }}}
345
345
* @group dsl
346
346
*/
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)
351
350
}
352
351
353
352
/** Returns a `Catch` object with no catch logic and the argument as the finally logic.
0 commit comments