Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a module in C++?

What does the term module refer to in the following sentence?

Don't allow exceptions to propagate across module boundaries.

This is rule 62 in C++ Coding Standards by Herb Sutter and Andrei Alexandrescu.


I have now read the book, so I would like to quote the section summary, which I think adds some clarity:

Don't throw stones into your neighbor’s garden: There is no ubiquitous binary standard for C++ exception handling. Don't allow exceptions to propagate between two pieces of code unless you control the compiler and compiler options used to build both sides; otherwise, the modules might not support compatible implementations for exception propagation. Typically, this boils down to: Don’t let exceptions propagate across module/subsystem boundaries.

like image 504
sourcenouveau Avatar asked Feb 05 '13 18:02

sourcenouveau


1 Answers

That's a good question. The C++ standard doesn't use the word module (I don't think, at least), and the usual everyday meaning is something like a translation unit. Except that that can't be what Herb and Andrei mean, since the real purpose of using exceptions is to propagate up out of the local body of code—otherwise, you'd use return codes.

I can only guess, but they probably mean something that might reasonably be implemented in a different DLL. Propagating exceptions accross DLL boundaries might be a problem, if the DLL's have been compiled with a different compiler, or use a different language. Otherwise...

It's usually considered best practice to have a single try/catch block in main (or in some other high level function, in each thread), and catch all exceptions there, regardless of where they come from. And there are no problems with modern compilers when you do this.

like image 54
James Kanze Avatar answered Nov 10 '22 01:11

James Kanze