Allowing SecurityException to propagate during actor system termination

17 views
Skip to first unread message

Christopher Hunt

unread,
Nov 12, 2017, 10:48:02 PM11/12/17
to Akka User List
Hi everyone,

I have a situation where I need to call System.exit upon an actor system having terminated. In some runtime situations, a SecurityException will be thrown and I need that to be propagated as an unhandled exception. I can go into the details of why if required, but my question is how to enable this. Here's my existing termination handler which does what I want. However, I'm wondering if there's a better way given that onComplete and friends all swallow exceptions and pass them onto the Dispatcher's reporter:

  system.whenTerminated
   
.andThen {
     
case _ =>
       
new Thread({ () =>
          println
("Exiting")
         
System.exit(exitStatus.getOrElse(1))
       
}: Runnable).start()
   
}


Cheers,
-C

Viktor Klang

unread,
Nov 13, 2017, 5:13:01 AM11/13/17
to Akka User List
When you say "unhandled exception" you mean "uncaught exception"?

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Christopher Hunt

unread,
Nov 13, 2017, 7:31:01 AM11/13/17
to akka...@googlegroups.com
Ah yes, uncaught. Thanks for the correction. 
You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/gZkCvLWhyGc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Viktor Klang

unread,
Nov 13, 2017, 7:43:23 AM11/13/17
to Akka User List
Depends on what you want to achieve. You can always do Thread.currentThread.getUncaughtExeptionHandler and pass your exception in manually (if you don't want to throw a Fatal exception or provide your own `reporter` (to the ExecutionContext).

To unsubscribe from this group and all its topics, send an email to akka-user+unsubscribe@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Christopher Hunt

unread,
Nov 13, 2017, 6:05:38 PM11/13/17
to akka...@googlegroups.com
Thanks Viktor, I’ve gone with your suggestion which I think is nice and explicit:

private val eh = Thread.currentThread().getUncaughtExceptionHandler

system.whenTerminated
  .andThen {
    case _ =>
      try {
        println("Exiting")
        System.exit(exitStatus.getOrElse(1))
      } catch {
        case se: SecurityException => eh.uncaughtException(Thread.currentThread(), se)
      }
  }
Reply all
Reply to author
Forward
0 new messages