yabola commented on PR #37779: URL: https://github.com/apache/spark/pull/37779#issuecomment-1252159912
To answer why `uncaughtExceptionHandler` in `Executor` doesn't catch error https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/executor/Executor.scala#L106 I have a simple little program to explain ` object TestExceptionHandler { val threadFactory = new ThreadFactoryBuilder().setDaemon(true).build() def main(args: Array[String]): Unit = { val service = Executors.newSingleThreadExecutor(threadFactory) val runLoop = new Runnable() { override def run(): Unit = receiveLoop() } service.execute(runLoop) Thread.sleep(2 * 1000) } private def receiveLoop() { try { Executors.newSingleThreadExecutor(threadFactory).execute(new MessageLoop) } catch { case t: Throwable => { println("`receiveLoop` catch the Exception") } } } class MessageLoop extends Runnable { Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler) /** * This Exception will not be caught by `MyExceptionHandler`. It will be caught by `receiveLoop` */ if (1 == 1) { throw new UnsatisfiedLinkError("My Exception error, will be caught by receiveLoop") } override def run(): Unit = { println("MessageLoop run method.... ") /** * This Exception will be caught by `MyExceptionHandler` * (The premise is that the above Exception code needs to be commented out) */ if (1 == 1) { throw new UnsatisfiedLinkError("My Exception error, will be caught by `MyExceptionHandler` !") } } } class MyExceptionHandler extends Thread.UncaughtExceptionHandler { override def uncaughtException(t: Thread, e: Throwable): Unit = { println("`MyExceptionHandler` catch the Exception... ") } } } ` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
