Friday, October 27, 2017

Windows AMD64 ABI nuances part 3 -- why so concerned with exception handling?

When speaking about an ABI, exception handling comes up a lot.

Many programmers will roll their eyes and protest.
"I have barely any try/catch or throw or Windows __try/__except/__finally in my program, so why so concerned with exception handling?"

"One is all you need."

If all of your exceptions are "fail fast" (exit(), ExitProcess(), TerminateProcess(), etc.),
then sure, nevermind.

More common than try/catch or __try/__except/__finally is functions with locals with destructors.
Every successful construction is conceptually paired with a "finally destroy".

 struct A
 {
   A();
   ~A();
 };

 void f() { A a, b; }

 This function has an exception handler.
 It looks like:

 void f()
 {
   construct a
   try
   {
      construct b
      detroy b
   }
   finally
   {
      destroy a
   }
 }

 - Jay

No comments:

Post a Comment