Postmortem: Template unittests are bad & you shouldn't catch Error

Ali Çehreli acehreli at yahoo.com
Thu Oct 22 20:23:49 UTC 2020


On 10/21/20 9:04 PM, Mathias LANG wrote:

 > *do not catch Error*. Catching
 > `Error` is a sin, a crime, and every catch of `Error` derivative should
 > have you outraged. It is in direct violation of the specs. And
 > obviously, it's also incompatible with scheme that do not throw an 
`Error`.

That's true but I will recommend catching Error in both of my upcoming 
DConf Online presentations. :)

1) Thread entry functions should catch and report any Throwable. 
Otherwise, main thread will see only a timeout and stack trace of the 
worker will lost.

2) extern(C) D library functions must catch Throwable and return 
non-zero error code because the caller is highly likely not going to be 
able to handle the situation. Even when our library function is called 
from D, meaning that it can handle D exceptions, we cannot be sure that 
we are in the main thread. (Can we detect that?). If I'm not mistaken, 
only the main thread dumps stack trace for Error; so, extern(C) function 
catching and reporting is essential.

Is my thinking correct?

Ali



More information about the Digitalmars-d mailing list