fail

Call this to end your program with an error message for the user, and no ugly stack trace. The error message is sent to stderr and the errorlevel is set to non-zero.

This is exception-safe, all cleanup code gets run.

Your program's name is automatically detected from std.file.thisExePath.

Note, on DMD 2.064.2, the error message is displayed BEFORE the exception is thrown. So if you catch the Fail exception, the message will have already been displayed. This is due to limitations in the older druntime, and is fixed on DMD 2.065 and up.

void
fail
(
string msg
)

Examples

fail("You forgot to provide a destination!");

// Output on DMD 2.065 and up:
// yourProgramName: ERROR: You forgot to provide a destination!

// Output on DMD 2.064.2:
// yourProgramName: ERROR: You forgot to provide a destination!
// scriptlike.fail.Fail

Meta