Skip to content

Commit 421955c

Browse files
committed
SI-9350 Preserve exceptions
On error, rethrow the exception or `IllegalArgumentException`.
1 parent 7a07693 commit 421955c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ trait ScalaClassLoader extends JClassLoader {
4747
def create(path: String): AnyRef =
4848
tryToInitializeClass[AnyRef](path).map(_.newInstance()).orNull
4949

50-
/** Create an instance with ctor args, or invoke errorFn before throwing FatalError. */
50+
/** Create an instance with ctor args, or invoke errorFn before throwing. */
5151
def create[T <: AnyRef : ClassTag](path: String, errorFn: String => Unit)(args: AnyRef*): T = {
52-
def fail(msg: String) = {
53-
errorFn(msg)
54-
throw FatalError(msg)
55-
}
52+
def fail(msg: String) = error(msg, new IllegalArgumentException(msg))
53+
def error(msg: String, e: Throwable) = { errorFn(msg) ; throw e }
5654
try {
5755
val clazz = Class.forName(path, /*initialize =*/ true, /*loader =*/ this)
5856
if (classTag[T].runtimeClass isAssignableFrom clazz) {
@@ -69,10 +67,10 @@ trait ScalaClassLoader extends JClassLoader {
6967
fail(s"Not a ${classTag[T]}: ${path}")
7068
}
7169
} catch {
72-
case _: ClassNotFoundException =>
73-
fail(s"Class not found: ${path}")
70+
case e: ClassNotFoundException =>
71+
error(s"Class not found: ${path}", e)
7472
case e @ (_: LinkageError | _: ReflectiveOperationException) =>
75-
fail(s"Unable to create instance: ${path}: ${e.toString}")
73+
error(s"Unable to create instance: ${path}: ${e.toString}", e)
7674
}
7775
}
7876

0 commit comments

Comments
 (0)