Just interested.
Can I throw exception somehow that debugger will think it was thrown in another place?
Asked
Active
Viewed 66 times
1

Vyacheslav
- 559
- 2
- 11
-
1maybe if the pdb does not match the actual code – Cee McSharpface Nov 13 '19 at 13:59
-
1interesting question yes...but why? What's the use case? – ADyson Nov 13 '19 at 14:01
-
2Why do you want to do this....what problem are you trying to actually solve? – mason Nov 13 '19 at 14:01
-
What debugger are you using? Probably Visual Studio 20xx zzz edition – BurnsBA Nov 13 '19 at 14:04
-
`Thread.Abort` does that, to another thread, in a completely different call stack and call site, but it's not predictable (it's thrown at whatever place the thread is currently executing), and it always throws a `ThreadAbortException`. Is that useful for you? Another option might be faking exception dispatch info, that's what async `Task` code does to improve your debugging experience. – Luaan Nov 13 '19 at 14:05
-
@ADyson care to explain in more detail how you *could* throw an exception where the debugger will think it was thrown in another place? Specifically, could you answer, how would the CLR create the stack trace since this is done *from the point of the throw*... how would you *fake the stack trace*? – Trevor Nov 13 '19 at 14:16
-
1@Renat that's fault injection, different concept and it doesn't *fake* where an exception occur's. – Trevor Nov 13 '19 at 14:19
-
@Çöđěxěŕ why are you asking that question to me? I didn't say it was possible. I was more interested in what someone would want to do with it, if it turned out to be possible. I agree with you, I'd be pretty surprised if it could actually be done. – ADyson Nov 13 '19 at 14:19
-
1@ADyson `interesting question yes...but why?` then I must of misunderstood this... :) You must be saying `yes` to an interesting question. I was thinking you were saying `yes` it *can* be done. – Trevor Nov 13 '19 at 14:20
-
1@Çöđěxěŕ Correct. I meant _"This is definitely an interesting question...but why would you want to do such a thing?"_ . Does that make more sense? :-) – ADyson Nov 13 '19 at 14:21
-
1@ADyson yes, sorry, simple miss-understanding. – Trevor Nov 13 '19 at 14:22
-
@Renat No, that's not what the OP is asking about. Fault injection throws an exception but it doesn't hide or change where the exception occurred (a thing which, IMO, is really a logical impossibility). – ADyson Nov 13 '19 at 14:24
-
To be honest, there's no logical reason to ever even need to be able to do this. What would be gained from *trying* to do so, nothing. This is not possible, you can't *throw* an exception and say `hey not from here, but from there` and fake the stack trace as the stack trace is created where the exception was created. – Trevor Nov 13 '19 at 14:28
-
"there's no logical reason to ever even need to be able to do this" -- eh, someone might attempt this to obfuscate code, make it more difficult to reverse engineering. Will this be worthwhile in practice? Well....... – BurnsBA Nov 13 '19 at 14:33
-
@BurnsBA but if they do that, it also makes it impossible for them debug faults in their own software, and therefore provide support to users. So I'd say it would be likely to cause more problems than it solves. – ADyson Nov 13 '19 at 14:41
-
I was just curious how debugger detects where exception really happened. I don't need to solve any problem. – Vyacheslav Nov 13 '19 at 14:54
-
Thank you for all of your answers. – Vyacheslav Nov 13 '19 at 14:55