-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Desktop: User-friendly crash of the window when exception is thrown inside Composable (show alert to the user) #663
Comments
Could it be so that the window doesn't "freeze", or at least have an api to restart its event loop? Right now if a ui exception happens, you are forced to close that window, there's no way to keep the app running on it. But since the window freezes for good, in my app i had to hack a solution where the DefaultUncaughtExceptionHandler quickly closes the old window and opens a new one, "resuming" the app there. But it doesn't look good ui-wise (window closing-opening out of nowhere, since an exception is unexpected), and i need to manually copy the old-window's position/size/etc to the new one. It would be nicer to simply recompose in the original window instead. I came from javafx, where an exception in ui thread simply triggers a dialog, but the event loop stays running. You can suppress the dialog and handle the exception in other ways inside your app. |
Also i want to note that you can't close the frozen window if it is undecorated, since the manually drawn window controls are in compose code (Alt-f4 still works though) |
Fixes JetBrains/compose-multiplatform#663 If users use Thread.currentThread().setUncaughtExceptionHandler, then now they should start application with
Now (1.0.0-rc3) we show a dialog on error by default, and close the window. Users can override it via |
There is a bug in 1.0.1. Because of it we can't override Until then, the alternative is to set it via ComposeWindow:
|
Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains/compose-multiplatform#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
1. introduce ComposeWindow.exceptionHandler - can catch exceptions happened during recomposition, render, or event handling 2. if we use ComposeWindow directly, we don't change Swing behaviour - we just log the exception, and throw it further. 3. if we use Composable Window API, we show an error dialog and close the window. Users can override that via LocalWindowExceptionFactory. Fixes JetBrains#663 Change-Id: I87c6e1d615951babbb070004cdcb5b87c07dc94f Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true # Conflicts: # compose/ui/ui/src/desktopTest/kotlin/androidx/compose/ui/awt/ComposeWindowTest.kt
can you show an example how to keep the app running after catching an exception like this? i can't get it to work. a compose exception always freezes the app. no way of recovery. |
Overriding The existing ticket for it seemed to be #1764. Setting It also leads me to wonder why setting the factory doesn't work... is it the case that it only works if you set it before displaying any windows? 🤔 |
Currently if we have a java exception inside Composable function we stop the rendering loop.
And user just sees the frozen window (but with ability to close it).
Usually this kind of exception is a bug that should be fixed by the developer (IO exceptions shouldn't be thrown in Composable).
Possible solutions:
The text was updated successfully, but these errors were encountered: