dimanche 26 juin 2016

Error reporting knowing where it is in the code

I have a stream called "err" which is in the namespace Errors. This is how the developer is meant to report errors in a user friendly way. So when something goes wrong the dev will write the error message as such:

Errors::err << "Oh no. That was a bad thing.";

Is it possible to use the preprocessor to append [__FILE__:__LINE__] to the error message without changing the current error reporting style? I.e. the above command would now (after preprocessing magic) output this to an error file:

Oh no. That was a bad thing. [file.cc:20]

I have tried this myself, but the C Preprocessor doesn't seem to like namespaces, and I don't feel I can go replacing "err" everywhere in the code - which would be an even bigger issue if a dev decides to use using Errors::err or using namespace Errors.

In the scope of what I want to achieve, is the C-Preprocessor fundamentally incompatible with the coding style? If so are there any other methods (perhaps Makefile based?) to do what I wish?

Aucun commentaire:

Enregistrer un commentaire