www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13554] New: adding ExitError which can be thrown to 'exit

https://issues.dlang.org/show_bug.cgi?id=13554

          Issue ID: 13554
           Summary: adding ExitError which can be thrown to 'exit with
                    exit code'
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: ketmar ketmar.no-ip.org

Created attachment 1438
  --> https://issues.dlang.org/attachment.cgi?id=1438&action=edit
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()!

--
Sep 28 2014