digitalmars.D.learn - close program by code
- pgtkda (1/1) Jun 26 2014 How can i close my application by code?
- FreeSlave (7/8) Jun 26 2014 Do you mean exit status? Just call exit function from C library.
- pgtkda (2/10) Jun 26 2014 wow, thank you very much :)
- John Colvin (3/11) Jun 26 2014 Will destructors and/or scope statements be executed if you exit
- Rene Zwanenburg (4/19) Jun 26 2014 They won't. Same for module destructors.
- Chris Nicholson-Sauls (7/10) Jun 26 2014 I really wish this wasn't the answer, but for some programs I've
- H. S. Teoh via Digitalmars-d-learn (33/46) Jun 26 2014 I've done the same for my own programs:
- FreeSlave (3/21) Jun 26 2014 Module destructors are called. At least in DMD v2.065. I believe
On Thursday, 26 June 2014 at 09:05:23 UTC, pgtkda wrote:How can i close my application by code?Do you mean exit status? Just call exit function from C library. import std.c.stdlib; void main() { exit(0); }
Jun 26 2014
On Thursday, 26 June 2014 at 09:58:50 UTC, FreeSlave wrote:On Thursday, 26 June 2014 at 09:05:23 UTC, pgtkda wrote:wow, thank you very much :)How can i close my application by code?Do you mean exit status? Just call exit function from C library. import std.c.stdlib; void main() { exit(0); }
Jun 26 2014
On Thursday, 26 June 2014 at 09:58:50 UTC, FreeSlave wrote:On Thursday, 26 June 2014 at 09:05:23 UTC, pgtkda wrote:Will destructors and/or scope statements be executed if you exit this way?How can i close my application by code?Do you mean exit status? Just call exit function from C library. import std.c.stdlib; void main() { exit(0); }
Jun 26 2014
On Thursday, 26 June 2014 at 10:40:00 UTC, John Colvin wrote:On Thursday, 26 June 2014 at 09:58:50 UTC, FreeSlave wrote:They won't. Same for module destructors. If you need those to work, another option is to throw some custom Exception type which is only caught in main.On Thursday, 26 June 2014 at 09:05:23 UTC, pgtkda wrote:Will destructors and/or scope statements be executed if you exit this way?How can i close my application by code?Do you mean exit status? Just call exit function from C library. import std.c.stdlib; void main() { exit(0); }
Jun 26 2014
On Thursday, 26 June 2014 at 11:07:37 UTC, Rene Zwanenburg wrote:They won't. Same for module destructors. If you need those to work, another option is to throw some custom Exception type which is only caught in main.I really wish this wasn't the answer, but for some programs I've had to resort to it myself. For at least one I've defined an Exception type that carries a status code payload to be returned by main. D needs its own exit(). There's been this request in the bugzilla since 2009: https://issues.dlang.org/show_bug.cgi?id=3462
Jun 26 2014
On Thu, Jun 26, 2014 at 01:23:17PM +0000, Chris Nicholson-Sauls via Digitalmars-d-learn wrote:On Thursday, 26 June 2014 at 11:07:37 UTC, Rene Zwanenburg wrote:I've done the same for my own programs: class ExitException : Exception { int status; this(int _status, string file=__FILE__, size_t line=__LINE__) { super(file,line); status = _status; } } void exit(int status=0) { throw new ExitException(status); } int main(string[] args) { try { ... return 0; } catch(ExitException e) { return e.status; } catch(Exception e) { ... // real exception here return 1; } } It works reasonably well for single-threaded program, but as the following bug states, there's no nice way to terminate a multithreaded program:They won't. Same for module destructors. If you need those to work, another option is to throw some custom Exception type which is only caught in main.I really wish this wasn't the answer, but for some programs I've had to resort to it myself. For at least one I've defined an Exception type that carries a status code payload to be returned by main. D needs its own exit().There's been this request in the bugzilla since 2009: https://issues.dlang.org/show_bug.cgi?id=3462If you have any good ideas, please chime in on the bug report! T -- "I'm not childish; I'm just in touch with the child within!" - RL
Jun 26 2014
On Thursday, 26 June 2014 at 11:07:37 UTC, Rene Zwanenburg wrote:On Thursday, 26 June 2014 at 10:40:00 UTC, John Colvin wrote:Module destructors are called. At least in DMD v2.065. I believe d runtime automatically register this with atexit function.On Thursday, 26 June 2014 at 09:58:50 UTC, FreeSlave wrote:They won't. Same for module destructors.On Thursday, 26 June 2014 at 09:05:23 UTC, pgtkda wrote:Will destructors and/or scope statements be executed if you exit this way?How can i close my application by code?Do you mean exit status? Just call exit function from C library. import std.c.stdlib; void main() { exit(0); }
Jun 26 2014