hidden passing of __FILE__ and __LINE__ into function

Dmitry via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 17 03:22:47 PDT 2017


Hi there.

Currently for messages about errors I use code like this:

     void add(string name, ref Scene scene)
     {
         if (name in listOfScenes)
         {
             EError(__FILE__, __LINE__, "scene already exists".L, 
quoted(name));
         }
     ...
     }

Is there way for avoid using (avoid writing) `__FILE__` and 
`__LINE__` in each call? I.e. I want use simple

     EError("scene already exists".L, quoted(name));

but function `EError` must print info (file and line) of where 
was called.

P.S. `EError` just prints info into console, result for this 
example is:

> [Error] (source\core\EScene.d, 35) Scene already exists: "Scene 
> 1"

and code is:

     void EError(S...)(S args)
     {
         write("[Error] (", args[0], ", ", args[1], ") ", 
args[2..$], '\n');}
     }



More information about the Digitalmars-d-learn mailing list