What is the best way to stop App after exception?
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 15 08:49:17 PST 2016
On Monday, February 15, 2016 15:38:07 Suliman via Digitalmars-d-learn wrote:
> On Monday, 15 February 2016 at 15:17:01 UTC, tcak wrote:
> > Since C's "exit" function is not liked, best thing you can do
> > is to throw an Error when you want to close the program. You
> > are not supposed to catch Errors. So, it eventually will stop
> > the currently running thread.
>
> but if I throw exception it's handled in instance of class Config
> and it's not go to main...
>
> And what the reason to not add support of C's "exit"?
You can call C's exit from D, but it won't shut down the app cleanly. It
_can't_ shut down the app cleanly. It can't even do that in C. For an
application to shut down cleanly, all of its threads must exit cleanly,
which requires that the programmer tell them to shut down cleanly (you can't
just have them magically exit cleanly when they're in the middle of
running), and of course, main has to exit properly so that the runtime has a
chance to shut things down properly. That can be by returning from main or
by having an Exception or Error bubble out of it, but simply calling exit()
would kill the program without letting the runtime - or anything in your
program - shut down cleanly.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list