File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -65,4 +65,18 @@ final class StringOps(private val s: String) extends AnyVal {
65
65
66
66
private def parse [A ](f : String => A ): NumberFormatException Either A = Either .catchOnly[NumberFormatException ](f(s))
67
67
68
+ /**
69
+ * Wraps a `String` in `Throwable`.
70
+ */
71
+ @ inline def asThrowable : Throwable = new Throwable (s)
72
+
73
+ /**
74
+ * Wraps a `String` in `Error`.
75
+ */
76
+ @ inline def asError : Error = new Error (s)
77
+
78
+ /**
79
+ * Wraps a `String` in `Exception`.
80
+ */
81
+ @ inline def asException : Exception = new Exception (s)
68
82
}
Original file line number Diff line number Diff line change @@ -173,6 +173,14 @@ class StringSyntaxTests extends MouseSuite {
173
173
}
174
174
}
175
175
176
+ test(" asThrowable, asError and asException" ) {
177
+ forAll { s : String =>
178
+ s.asThrowable.toString should === (new Throwable (s).toString)
179
+ s.asError.toString should === (new Error (s).toString)
180
+ s.asException.toString should === (new Exception (s).toString)
181
+ }
182
+ }
183
+
176
184
}
177
185
178
186
final class EitherIdOps [A ](val obj : A ) extends AnyVal {
You can’t perform that action at this time.
0 commit comments