"catch" not catching the correct exception

Shachar Shemesh shachar at weka.io
Thu Jul 26 05:52:51 UTC 2018


Under mecca, we're using GC free exceptions.

I have code that uses mkEx 
(https://github.com/weka-io/mecca/blob/master/src/mecca/lib/exception.d#L307). 
Essentially, it constructs an exception in place inside a fiber-local 
buffer. The construction code seems correct, and the parent seems set 
correctly (Exception).

When thrown, however, a catch for Exception does not catch it. It is 
caught if we try to catch Throwable, and also if we try to catch 
FiberInterrupt (a class deriving directly from Throwable).

Thinking the buffer might have gotten corrupted by one of the scope 
exits, I've added the following code:

     catch (Exception ex) {
         // Code that should have run goes here
     }
     catch(Throwable ex) {
         META!"XXX NONONONONO caught %s of type %s son of 
%s"(cast(void*)ex, ex.classinfo.name, ex.classinfo.base.name);
         LOG_EXCEPTION(ex);
         throw ex;
     }

When run, I get the following log:
META XXX NONONONONO caught 0x00007F1C616F39B0 of type 
weka.bucket.exceptions.NotBucketLeader son of object.Exception


It seems immediately obvious that the problem is not with using a static 
buffer for the exception (at least, it does not seem to be corrupted), 
but something else. Somehow, the catch matching does not work.

At which point I'm stuck. I don't know how D's catch matching works, so 
I don't know where to continue looking.

The problem does not happen consistently, but does happen frequently 
enough for me to be able to reproduce it when needed.

I need suggestions on how to debug this.

Thank you,
Shachar


More information about the Digitalmars-d mailing list