1

I've seen a number of articles, and questions all of which focus on the cost of exceptions, performance benchmarks, so and so.

But nothing really seems to explain Why it is so slow. What really happens under-the-hood so that its magnitudes slower when one is thrown. Most articles just say stack unwinding is what makes it slow. But I don't understand why that makes it magnitudes slower.

From a brief understanding of SEH, basically every time a thread enters a try block, it has add say, some kind of a marker to that location onto its Exception Chain in the TIB. That has its costs, while trying to walk back the stack. I understand that part. But I doubt that's even half the story considering the magnitude of the performance loss. Also, why do you even have to unwind the stack if the exception is being caught in the same function. Why is that case still equally slow?

Could someone please explain what really is going on in simple terms?

coolfool99
  • 19
  • 2
  • Why would you enter the assumption that stack-unwinding *isn't* slow? – Moo-Juice Mar 28 '15 at 14:29
  • Its not. But as I said, if it were the whole story, things should be a lot faster than what we generally experience. With my limited understanding, I suspect, there's somekind of marshalling/serialization of metadata, resulting in Cache misses or something more that's adding up in the process. If its solely, stack-unwinding I'd like to understand how the CLR handles that exactly. – coolfool99 Mar 28 '15 at 14:32
  • 2
    http://stackoverflow.com/a/12289900/17034 – Hans Passant Mar 28 '15 at 15:14
  • possible duplicate of [How does the catch keyword determine the type of exception that was thrown?](http://stackoverflow.com/questions/12289027/how-does-the-catch-keyword-determine-the-type-of-exception-that-was-thrown) – btevfik Mar 29 '15 at 03:14

0 Answers0