Hi, I was wondering why runtime exceptions in actors are not by default dumped to stdout like everything else? Since it currently silently catches the exception.. It is confusing in the beginning. I think it should at least be mentioned in the docs.
SlimerDudeWed 7 May 2014
why runtime exceptions in actors are not by default dumped to stdout
All Actor calls are wrapped up in an Future instance. When you call Future.get() any Err caught inside the Actor is rethrown to you. The problem is that Fantom doesn't know when or if that get() call will ever be made. In effect, the Err is sat there waiting, but you've already discarded the Future reference, so... silence.
If it were to log every Err just in case, then it could get very noisy, and very annoying for those who have implemented Err handlers.
I think it should at least be mentioned in the docs.
Yeah, I remember this catching me out when I started Fantom. I think it should be made more explicit in the docs, as I can't find any obvious mention of this behaviour.
Interesting, I am indeed not calling future.get... Is there any reason why I should? And is there a way to do something like a global handler or something? I can't find anything in the Future class... Currently, I am just wrapping the code in try/catch.
Nice library BTW, I may switch to it soon.. Thanks
SlimerDudeWed 7 May 2014
Hi,
future.get... Is there any reason why I should?
The Actor receive() methods can return objects - either the result of some computation, or some object being stored in the thread. Future.get() waits for the message to finish processing and returns the result.
is there something like a global handler
Nope. Just wrap every Actor handler method in a try / catch, like you are doing. That's what Synchronized.async() does.
brianWed 7 May 2014
Agreed, we should definitely document that! I added the following section to the actor chapter:
When an actor raises an exception processing a message in its receive callback, the error is made available in the Future. However if the Future is never checked, then the error is silently ignored. Unfortunately the system cannot know if the error is going to be handled by client code via the Future.
To prevent errors from silently occurring, the following design patterns are recommended:
each message should clearly identify who is responsible for processing the error
if the actor is responsible for errors, then it should log the error
if the client is responsible for errors, then it must check the Future and handle errors
As a general principle, messages processed synchronously get handled by the client. But async messages should probably get logged by the actor since its unlikely the client is doing anything with the Future.
ahhatemThu 8 May 2014
Very nice. Can you please add a clarification that the Future object is checked for errors when calling Future.get.
brianThu 8 May 2014
I tweaked prose a bit for that and also Steve's comments
ahhatem Wed 7 May 2014
Hi, I was wondering why runtime exceptions in actors are not by default dumped to stdout like everything else? Since it currently silently catches the exception.. It is confusing in the beginning. I think it should at least be mentioned in the docs.
SlimerDude Wed 7 May 2014
All Actor calls are wrapped up in an
Future
instance. When you callFuture.get()
any Err caught inside the Actor is rethrown to you. The problem is that Fantom doesn't know when or if thatget()
call will ever be made. In effect, the Err is sat there waiting, but you've already discarded the Future reference, so... silence.If it were to log every Err just in case, then it could get very noisy, and very annoying for those who have implemented Err handlers.
Yeah, I remember this catching me out when I started Fantom. I think it should be made more explicit in the docs, as I can't find any obvious mention of this behaviour.
If you use Synchronized.async() from afConcurrent, then that will log any caught Errs.
ahhatem Wed 7 May 2014
Interesting, I am indeed not calling
future.get
... Is there any reason why I should? And is there a way to do something like a global handler or something? I can't find anything in theFuture
class... Currently, I am just wrapping the code in try/catch.Nice library BTW, I may switch to it soon.. Thanks
SlimerDude Wed 7 May 2014
Hi,
The Actor
receive()
methods can return objects - either the result of some computation, or some object being stored in the thread.Future.get()
waits for the message to finish processing and returns the result.Nope. Just wrap every Actor handler method in a try / catch, like you are doing. That's what Synchronized.async() does.
brian Wed 7 May 2014
Agreed, we should definitely document that! I added the following section to the actor chapter:
When an actor raises an exception processing a message in its receive callback, the error is made available in the Future. However if the Future is never checked, then the error is silently ignored. Unfortunately the system cannot know if the error is going to be handled by client code via the Future.
To prevent errors from silently occurring, the following design patterns are recommended:
As a general principle, messages processed synchronously get handled by the client. But async messages should probably get logged by the actor since its unlikely the client is doing anything with the Future.
ahhatem Thu 8 May 2014
Very nice. Can you please add a clarification that the Future object is checked for errors when calling
Future.get
.brian Thu 8 May 2014
I tweaked prose a bit for that and also Steve's comments