Change default logging for unhandled exceptions
See original GitHub issueCurrently, an unhandled exception thrown in a UniTask
will be logged as a warning. Normally, an unhandled exception would be logged by Unity with Debug.LogException()
. This behavior can be changed by setting UniTaskScheduler.UnobservedExceptionWriteLogType
:
UniTaskScheduler.UnobservedExceptionWriteLogType = LogType.Exception;
I think it’s good that the behavior can be customized, but it would be better to have the default behavior match what Unity does by default.
If this is acceptable, I would be happy to open a pull request for the work! 😁
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Logging uncaught exceptions in Python
Use a custom logger with an example handler. This one changes the unhandled exception to go to stdout rather than stderr, but you...
Read more >NET 6 breaking change: Exception handling in hosting - .NET
NET 6 breaking change in core .NET libraries where unhandled exceptions from a BackgroundService are logged instead of lost.
Read more >Configure Django to log exceptions in production
Django default logging behaviour for unhandled exceptions is: # With DEBUG=True (Development). Log the exception on console/stream.
Read more >Unhandled Exception Logging - Embrace.io
Embrace automatically logs all unhandled exceptions thrown by your application, ... By default, only exceptions thrown on the main Unity thread are logged....
Read more >Logging uncaught exceptions in Python applications
One situation that you want to make sure you get in your logs is when an unhandled exception occurs in the program.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@randomPoison
In your example, the
Throw from async Task
is not captured. Normal tasks must be set explicitly viaTaskScheduler.UnobservedTaskException
. In other words, this is where we identify whether it’s Unobserved or not.It’s also listed at the top in Error.
The problem, however, is that, as you say, the InnerException dump is Log-unfriendly in Unity. It’s a choice between making the Log jump friendly or marking it as Unobserved.
Now, I think most people don’t understand the meaning of Uobserved in the first place, and jump-friendly seems to benefit a lot of people. Ok, I’d like to make Exception the default, at least in v2.
You’re right, there’s not a lot of harm in leaving that option in there, especially if it’s set to log using
Debug.LogException()
by default. However, there’s also not much value in leaving it in I think. It’s a bad practice to log exceptions with anything other thanDebug.LogException()
, so leaving that option in just allows users to make their projects harder to debug with no benefit. It also adds a bit of unnecessary code complexity toUniTaskScheduler
. So even if there’s not much harm in leaving it, I only see benefits to removing it.That said, once the default is changed to
Debug.LogException()
my main concern will be addressed! So it won’t matter a ton to me if you do leave it in.