What is the best way to stop App after exception?
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 15 16:23:07 PST 2016
On Monday, 15 February 2016 at 15:38:07 UTC, Suliman 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...
>
Either rethrow the original Exception:
catch(Exception e)
{
writeln(e.msg);
throw e;
}
In this case, if nothing else catches the exception, then it will
go back to main. If anything else does catch it, it can rethrow.
Or you can do as suggested above throw a new Error:
catch(Exception e)
{
writeln(e.msg);
throw new Error(e.msg);
}
If nothing is catching Throwable or Error (and nothing should
be), then the error will go all the way back to main just fine.
More information about the Digitalmars-d-learn
mailing list