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/

Reply via email to