August 20, 2012
> You could define a custom ExitException and throw that, catching it at
> the top level and returning the error code stored inside it, from
> main().  Not ideal, but it would work.

Thi is really not ideal, since this is for a argument-parser, --help should print the help and then exit.

August 20, 2012
> Or the D runtime could just use the "atexit" function defined in
> stdlib.h. Just add a callback which terminates the D runtime.
>
> http://pubs.opengroup.org/onlinepubs/009695299/functions/atexit.html

If i interpret it correctly, a call to Runtime.terminate() (as I am doing right now), is the only and correct way?

August 21, 2012
On 2012-08-20 22:04, David wrote:

> If i interpret it correctly, a call to Runtime.terminate() (as I am
> doing right now), is the only and correct way?

I would think so.

-- 
/Jacob Carlborg
August 21, 2012
On Mon, 20 Aug 2012 21:03:25 +0100, David <d@dav1d.de> wrote:

>> You could define a custom ExitException and throw that, catching it at
>> the top level and returning the error code stored inside it, from
>> main().  Not ideal, but it would work.
>
> Thi is really not ideal

Didn't I just say that.. :p

"Not ideal, but it would work."
 - Regan Heath

> , since this is for a argument-parser, --help should print the help and then exit.

Still, it can be done..

int main(string[] args)
{
  int retval = 0;

  try
  {
   ParseArguments(args);
  }
  catch(ExitException e)
  {
    // Silent
    retval = e.retval;
  }
  catch(Exception e)
  {
    writefln("Error: %s", e...);
    retval = 1;
  }

  return retval;
}

void ParseArguments(string[] args)
{
  .. parse .. calls CmdHelp();
}

void CmdHelp()
{
  writeln(...);
  throw ExitException(0);
}

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
1 2
Next ›   Last »