On Sunday, 16 September 2012 at 21:12:42 UTC, deed wrote:
I did, but then I am not able to use writeln for debugging.
Is this restriction something new?
nothrow just means the function itself should not *exit* with an
exception. It is still legally allowed to call a throwing
function, provided promises to handles (catche) any thrown
exception. How it deals with the exception (silence/error) is up
to it. For example:
--------
void foo() nothrow
{
try
{
writeln("hello world!");
}
catch(Exception) { } //silence
//doStuff
}
--------
Of course, the "try catch do nothing" writting can get old, so
you can use std.exception's "collectException" too*;
--------
void foo() nothrow
{
collectException(writeln("hello world!"));
//doStuff
}
--------
*Though for me, the compiler sometimes still complains.
Or better yet, you *could* write a "debugWriteln()", which is
marked as @trusted nothrow:
--------
@trusted nothrow
void debugWriteln(Args...)(Args args) nothrow
{
try{writeln(args);}catch(Exception){};
}
void foo() nothrow
{
debugWriteln("hello world!");
//doStuff
}
--------
The @trusted is so that it can also be used inside safe functions
(which will exhibit the same issue). With this, you can log in
any function.