If the user gave any invalid options on the command-line,
the parsing function throws a Zend_Console_Getopt_Exception.
You should catch this exception in your application code.
You can use the parse() method to force the object
to parse the arguments. This is useful because you can invoke
parse() in a try block. If it passes,
you can be sure that the parsing won't throw an exception again.
The exception thrown has a custom method getUsageMessage(),
which returns as a string the formatted set of usage messages for
all declared options.
Example 124. Catching Getopt Exceptions
<?php
try {
$opts = new Zend_Console_Getopt('abp:');
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
Cases where parsing throws an exception include:
Option given is not recognized.
Option requires a parameter but none was given.
Option parameter is of the wrong type. E.g. a non-numeric string when an integer was required.




