Bug 13554 – adding ExitError which can be thrown to 'exit with exit code'

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-29T02:12:00Z
Last change time
2014-10-02T04:15:38Z
Assigned to
nobody
Creator
ketmar

Attachments

IDFilenameSummaryContent-TypeSize
1438ExitError.patchdruntime path for ExitErrortext/plain1397

Comments

Comment #0 by ketmar — 2014-09-29T02:12:08Z
Created attachment 1438 druntime path for ExitError there is no official thing like `exit(code);` to exit to OS with the given code. the common idiom is to throw some exception/error and wrap main() in try/catch if one wants to avoid ugly stack traces. this patch introduces ExitError class which can be thrown like an ordinary Throwable, yet runtime will not produce any messages for it and use it's arg as exit code. small one-line samples: import core.exception : ExitError; throw new ExitError(); this will exit with EXIT_FAILURE code import core.exception : ExitError; throw new ExitError(1); this will exit with specified code. import core.exception : ExitError; throw new ExitError(0); this will exit with zero code, which means EXIT_SUCCESS. and no stack traces and other messages, and no boilerplate code in main()!
Comment #1 by hsteoh — 2014-10-01T22:17:38Z
This seems to be a duplicate of issue #3462.
Comment #2 by hsteoh — 2014-10-01T22:18:33Z
Maybe you could attach your patch to the other issue and close this one as a duplicate?
Comment #3 by ketmar — 2014-10-02T04:15:38Z
(In reply to hsteoh from comment #2) > Maybe you could attach your patch to the other issue and close this one as a > duplicate? hm. i don't know how this will work with threads and never tested it (i'm not using multithreading alot, i prefer to fork() ;-). but yes, i can attach my patch there, no prob. *** This issue has been marked as a duplicate of issue 3462 ***