If you are not doing an emergency exit, you want to clear everything. For this purpose, I created ExitException
:
class ExitException : Exception
{
int rc;
@safe pure nothrow this(int rc, string file = __FILE__, size_t line = __LINE__)
{
super(null, file, line);
this.rc = rc;
}
}
You code the function main()
and then
int main(string[] args)
{
try
{
}
catch (ExitException e)
{
return e.rc;
}
return 0;
}
The moment you need to exit, you call
throw new ExitException(1);