Merge pull request #433 from akka/wip-2038-clarify-creation-failures-√

Clarifying the error message given when there's an InstantiationExceptio...
This commit is contained in:
viktorklang 2012-05-08 05:05:28 -07:00
commit 27d7490f92
2 changed files with 10 additions and 4 deletions

View file

@ -509,7 +509,14 @@ private[akka] class ActorCell(
checkReceiveTimeout checkReceiveTimeout
if (system.settings.DebugLifecycle) system.eventStream.publish(Debug(self.path.toString, clazz(created), "started (" + created + ")")) if (system.settings.DebugLifecycle) system.eventStream.publish(Debug(self.path.toString, clazz(created), "started (" + created + ")"))
} catch { } catch {
case NonFatal(e) throw ActorInitializationException(self, "exception during creation", e) case NonFatal(i: InstantiationException)
throw ActorInitializationException(self,
"""exception during creation, this problem is likely to occur because the class of the Actor you tried to create is either,
a non-static inner class (in which case make it a static inner class or use Props(new ...) or Props( new UntypedActorFactory ... )
or is missing an appropriate, reachable no-args constructor.
""", i)
case NonFatal(e)
throw ActorInitializationException(self, "exception during creation", e)
} }
} }

View file

@ -43,14 +43,14 @@ object Props {
* Scala API. * Scala API.
*/ */
def apply[T <: Actor: ClassManifest]: Props = def apply[T <: Actor: ClassManifest]: Props =
default.withCreator(implicitly[ClassManifest[T]].erasure.asInstanceOf[Class[_ <: Actor]].newInstance) default.withCreator(implicitly[ClassManifest[T]].erasure.asInstanceOf[Class[_ <: Actor]])
/** /**
* Returns a Props that has default values except for "creator" which will be a function that creates an instance * Returns a Props that has default values except for "creator" which will be a function that creates an instance
* of the supplied class using the default constructor. * of the supplied class using the default constructor.
*/ */
def apply(actorClass: Class[_ <: Actor]): Props = def apply(actorClass: Class[_ <: Actor]): Props =
default.withCreator(actorClass.newInstance) default.withCreator(actorClass)
/** /**
* Returns a Props that has default values except for "creator" which will be a function that creates an instance * Returns a Props that has default values except for "creator" which will be a function that creates an instance
@ -70,7 +70,6 @@ object Props {
def apply(behavior: ActorContext Actor.Receive): Props = def apply(behavior: ActorContext Actor.Receive): Props =
apply(new Actor { def receive = behavior(context) }) apply(new Actor { def receive = behavior(context) })
} }
/** /**