Search Issue Tracker
Won't Fix
Votes
0
Found in
2022.2.0a15
Issue ID
UUM-1562
Regression
No
Exceptions are not logged when thrown from "async Task"
How to reproduce:
1. Open project "LogsInAsync.zip"
2. In the Hierarchy window select "GameObject" GameObject
3. In the Inspector window press on three dots of the script Component and choose "Call Async Methods"
4. Observe the Console window
Expected result: Exception is logged
Actual result: Exception is not logged
Reproducible with: 2019.4.39f1, 2020.3.35f1, 2021.3.3f1, 2022.1.2f1, 2022.2.0a15
Reproducible on: macOS 11.6 (Intel)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Metal] "undeclared identifier 'RemapFoveatedRenderingResolve'" error is thrown when compiling a shader
- "NullReferenceException" is logged when adding a visual element to a list using the Item Template setting
- Errors are thrown and the view is not rendered properly when using Overlay Camera with Non-Default 2D Renderer
- Fog density value is not returned when using the Fog node in a sprite Shader Graph
- UI ToolKit ListView does not rebind some of the items when source data changes
Resolution Note:
This is normal C# behavior, by design:
- an async Task returning method will capture any exception raised within its body, so that that it can be handled by the consuming side (by awaiting within a try/catch bloc, calling task.Result, or task.Wait,...).
- so the exception is swallowed before the Unity runtime can see it as an unhandled exception, and as no other code awaits on the task object, it is somehow lost (ultimately, there will be an error happening when the Task objects gets garbage collected, but that won't produce a console entry).
The versions wrapped in an async void method don't have any way to capture and propagate to an awaiter, so those cases pass the exception to the runtime.