Simple implementation of __FUNCTION

Jacob Carlborg doob at me.com
Fri Nov 2 11:39:51 PDT 2012


On 2012-11-02 18:31, Rob T wrote:
> Thanks to input from the D community, I've managed to implement a
> reasonable way to log the name of a calling function. This is used for
> basic execution monitoring and for automated logging of exception errors.
>
> Here's what I did.
>
> template __FUNCTION()
> {
>     const char[] __FUNCTION = "__traits(identifier, __traits(parent, {}))";
> }
>
> Example use in code:
>
> throw new Exception( "Error: Function ", mixin(__FUNCTION!()) );
>
> writefln( "File: %s, Func: %s, Line: %d", __FILE__,
> mixin(__FUNCTION!()), __LINE__ );

That's pretty darn cool, well done :D .

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list