Skip to content
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

Exception logging only on highest call stack level? #96

Open
jowliwon opened this issue Jun 28, 2022 · 1 comment
Open

Exception logging only on highest call stack level? #96

jowliwon opened this issue Jun 28, 2022 · 1 comment
Labels

Comments

@jowliwon
Copy link

jowliwon commented Jun 28, 2022

While using OnException to catch exceptions. I sort of want to be able to inform the user of things going wrong with a dialog.
How ever, if the exception that gets thrown belongs to a sub in the call stack, the OnException will get triggered all the way to its origin place.
Is there any proper way to keep track if this is the first triggered 'OnException' in the call stack chain?
As in my case, there only needs to be one dialog triggered by this, and not lets say five, reporting on the same issue, just on different levels of the call stack.

public override void OnException(MethodExecutionArgs args)
{
//Some kind of if-statement
//Show exception in dialog window.
}

@Ralf1108
Copy link
Collaborator

I don't understand how there can be multiple exceptions in one user action. Do you mean when using concurrent/parallel method calls?

All in all I would prefer using the unhandled exception handler of your UI/message pump framework to intercept exceptions as last resort and then show the corresponding dialog.
For WPF check this out: WPF unhandled exception handler

If you really want to track the call stack chain longer than the lifetime of the aspect then you have to use a static variable or enforce a policy that the instance of the current method call have an interface which provides a property to store this information.
The stack trace can be retrieved via reflection and stack trace
But this solution would be a big code smell for me :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants