New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better handling of uncaught exceptions in main and user threads #3423
Better handling of uncaught exceptions in main and user threads #3423
Conversation
Suggested change in title: s/uncought/uncaught/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me, now we will have
Exception in thread "main"
Exception: java.lang.StringIndexOutOfBoundsException thrown from the UncaughtExceptionHandler in thread "main"
... (stacktrace)
when exception is thrown while rendering another exception 👍
I left one question about setDefaultUncaughtExceptionHandler
.
|
||
// ScalaNativeSpecific exception handler, used when executing user-provied handlers, in main | ||
// Duplicate in NativeThread.threadEntryPoint | ||
private[java] final def uncaughtExceptionInternal( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note] We come here when scala-native app fails with uncaught exception
try uncaughtException(t, e) | ||
catch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note]
here we catch the exception thrown while rendering another exception
def getDefaultUncaughtExceptionHandler(): UncaughtExceptionHandler = | ||
defaultExceptionHandler | ||
def setDefaultUncaughtHandler(eh: UncaughtExceptionHandler): Unit = | ||
def setDefaultUncaughtExceptionHandler(eh: UncaughtExceptionHandler): Unit = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a silly question, who calls setDefaultUncaughtExceptionHandler
? I couldn't find the caller of this method in this project, and ThreadGroup#uncaughtException
always goes this branch
scala-native/javalib/src/main/scala/java/lang/ThreadGroup.scala
Lines 222 to 225 in ac2460c
case null => | |
val threadName = s""""${thread.getName()}"""" | |
System.err.print(s"Exception in thread $threadName") | |
throwable.printStackTrace(System.err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, it's gonna be used by users like Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review changes approve -> request changes, just because CI is failing :)
Not just in the title, some places in the code also mention |
…Thread.UEH, move logic to nativelib
Fixes #3418