@@ -83,6 +83,10 @@ object Exception {
8383 * Pass a different value for rethrow if you want to probably
8484 * unwisely allow catching control exceptions and other throwables
8585 * which the rest of the world may expect to get through.
86+ * @tparam T result type of bodies used in try and catch blocks
87+ * @param pf Partial function used when applying catch logic to determine result value
88+ * @param fin Finally logic which if defined will be invoked after catch logic
89+ * @param rethrow Predicate on throwables determining when to rethrow a caught [[Throwable ]]
8690 */
8791 class Catch [+ T ](
8892 val pf : Catcher [T ],
@@ -105,10 +109,12 @@ object Exception {
105109 }
106110 finally fin foreach (_.invoke())
107111
108- /* Create an empty Try container with this Catch and the supplied `Finally`. */
109- def andFinally (body : => Unit ): Catch [T ] = fin match {
110- case None => new Catch (pf, Some (new Finally (body)), rethrow)
111- case Some (f) => new Catch (pf, Some (f and body), rethrow)
112+ /** Create a new Catch container from this object and the supplied finally body.
113+ * @param body The additional logic to apply after all existing finally bodies
114+ */
115+ def andFinally (body : => Unit ): Catch [T ] = {
116+ val appendedFin = fin map(_ and body) getOrElse new Finally (body)
117+ new Catch (pf, Some (appendedFin), rethrow)
112118 }
113119
114120 /** Apply this catch logic to the supplied body, mapping the result
@@ -117,13 +123,13 @@ object Exception {
117123 def opt [U >: T ](body : => U ): Option [U ] = toOption(Some (body))
118124
119125 /** Apply this catch logic to the supplied body, mapping the result
120- * into Either[Throwable, T] - Left(exception) if an exception was caught,
121- * Right(T) otherwise.
126+ * into ` Either[Throwable, T]` - ` Left(exception)` if an exception was caught,
127+ * ` Right(T)` otherwise.
122128 */
123129 def either [U >: T ](body : => U ): Either [Throwable , U ] = toEither(Right (body))
124130
125131 /** Apply this catch logic to the supplied body, mapping the result
126- * into Try[T] - Failure if an exception was caught, Success(T) otherwise.
132+ * into ` Try[T]` - ` Failure` if an exception was caught, ` Success(T)` otherwise.
127133 */
128134 def withTry [U >: T ](body : => U ): scala.util.Try [U ] = toTry(Success (body))
129135
0 commit comments