Steve Schveighoffer wrote:
What's hard about using something other than exceptions to print usage in short scripts?

This looks just as readable/easy to me:

import std.usage;

int main(string[] args)
{
   checkUsage(args.length > 1, "Usage: prog args");
   ....
}

I also would like to see stack traces in small scripts too, esp. when the script isn't throwing the exception.

Here's one example I used:

#!/usr/bin/env rdmd
import std.exception, std.file;
void main(string[] args) {
   enforce(args.length == 3,
      "Usage: trcopy file1 file2");
   auto tmp = args[2] ~ ".messedup";
   scope(failure) if (exists(tmp)) remove(tmp);
   copy(args[1], tmp);
   rename(tmp, args[2]);
}

It could end with at least a couple distinct exception types. Clearly we're not cutting the pie the right way. The right solution is - absent any handler, an exception leaking out of main() prints the message and exit(1).


Andrei
_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to