diff --git a/lemon/arg_parser.h b/lemon/arg_parser.h
--- a/lemon/arg_parser.h
+++ b/lemon/arg_parser.h
@@ -2,7 +2,7 @@
*
* This file is a part of LEMON, a generic C++ optimization library.
*
- * Copyright (C) 2003-2009
+ * Copyright (C) 2003-2010
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
*
@@ -34,6 +34,44 @@
namespace lemon {
+ ///Exception used by ArgParser
+ class ArgParserException : public Exception {
+ public:
+ enum Reason {
+ HELP, /// --help option was given
+ UNKNOWN_OPT, /// Unknown option was given
+ INVALID_OPT /// Invalid combination of options
+ };
+
+ private:
+ Reason _reason;
+
+ public:
+ ///Constructor
+ ArgParserException(Reason r) throw() : _reason(r) {}
+ ///Virtual destructor
+ virtual ~ArgParserException() throw() {}
+ ///A short description of the exception
+ virtual const char* what() const throw() {
+ switch(_reason)
+ {
+ case HELP:
+ return "lemon::ArgParseException: ask for help";
+ break;
+ case UNKNOWN_OPT:
+ return "lemon::ArgParseException: unknown option";
+ break;
+ case INVALID_OPT:
+ return "lemon::ArgParseException: invalid combination of options";
+ break;
+ }
+ return "";
+ }
+ ///Return the reason for the failure
+ Reason reason() const {return _reason; }
+ };
+
+
///Command line arguments parser
///\ingroup misc
@@ -116,6 +154,10 @@
const std::string &help,
void (*func)(void *),void *data);
+ bool _exit_on_problems;
+
+ void _terminate(ArgParserException::Reason reason) const;
+
public:
///Constructor
@@ -380,6 +422,11 @@
///not starting with a '-' character.
const std::vector &files() const { return _file_args; }
+ ///Throw instead of exit in case of problems
+ void throwOnProblems()
+ {
+ _exit_on_problems=false;
+ }
};
}