container icon indicating copy to clipboard operation
container copied to clipboard

Keep original stack trace when rethrowing exceptions

Open jesperll opened this issue 5 years ago • 4 comments

When calling Container.Dispose() if a single object throws an exception it gets rethrown in a way that replaces the original stacktrace with one that only includes Container.Dispose()

This makes it impossible to log what fails in a released app. All you get is Container.Dispose threw an exception.

If multiple objects throw exceptions they're wrapped in an AggregateException keeping their original stacktraces intact.

A better way would be to rethrow using ExceptionDispatchInfo.Capture(exceptions[0]).Throw(); This would keep the original stacktrace.

ExceptionDispatchInfo is available in NET45 and NETStandard10 so NET40 would need to keep throwing as it does today.

LifeTimecontainer.Dispose has the exact same issue

ConstructorResolution.ResolveDelegate and DynamicBuildPlanGenerationContext.GetBuildMethod may also have the issue but I'm not entirely sure what the consequence would be here

jesperll avatar Jul 28 '20 12:07 jesperll

Would you like to send a PR for this?

ENikS avatar Jul 28 '20 17:07 ENikS

I would love to send a PR but I'm unsure how that works with your project structure (submodules). Do I make a pull request against unitycontainer/container or unitycontainer/unity or both?

jesperll avatar Jul 29 '20 08:07 jesperll

The dispose implementation is in Container project

ENikS avatar Jul 29 '20 22:07 ENikS

@ENikS It looks like the PR tests are run only within the context of the container project and therefore not finding the rest of the needed classes making them fail with stuff completely unrelated to my changes. How do I get them to run in the context of the full project?

jesperll avatar Aug 05 '20 07:08 jesperll