diff options
author | Michi Henning <michi@zeroc.com> | 2006-08-29 03:05:35 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2006-08-29 03:05:35 +0000 |
commit | 867d62b25a8be3774677296dcd438da2ec6ea26c (patch) | |
tree | a337af523816a16f48851d084ce59d202e57eb68 /cpp/src/IceUtil | |
parent | Bugs 1339, 1325, 1335. (diff) | |
download | ice-867d62b25a8be3774677296dcd438da2ec6ea26c.tar.bz2 ice-867d62b25a8be3774677296dcd438da2ec6ea26c.tar.xz ice-867d62b25a8be3774677296dcd438da2ec6ea26c.zip |
Bug 1339.
Bug 1335 and 1325 for Ice-E.
Diffstat (limited to 'cpp/src/IceUtil')
-rw-r--r-- | cpp/src/IceUtil/CtrlCHandler.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IceUtil/Exception.cpp | 6 | ||||
-rwxr-xr-x | cpp/src/IceUtil/Options.cpp | 121 | ||||
-rw-r--r-- | cpp/src/IceUtil/RWRecMutex.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IceUtil/Random.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IceUtil/ThreadException.cpp | 10 | ||||
-rw-r--r-- | cpp/src/IceUtil/Unicode.cpp | 2 |
7 files changed, 106 insertions, 39 deletions
diff --git a/cpp/src/IceUtil/CtrlCHandler.cpp b/cpp/src/IceUtil/CtrlCHandler.cpp index 3520e4e72f7..63dd93a30fd 100644 --- a/cpp/src/IceUtil/CtrlCHandler.cpp +++ b/cpp/src/IceUtil/CtrlCHandler.cpp @@ -31,7 +31,7 @@ CtrlCHandlerException::CtrlCHandlerException(const char* file, int line) : static const char* ctrlCHandlerName = "IceUtil::CtrlCHandlerException"; -const string +string CtrlCHandlerException::ice_name() const { return ctrlCHandlerName; diff --git a/cpp/src/IceUtil/Exception.cpp b/cpp/src/IceUtil/Exception.cpp index 94ed2f890d7..f61cbfda023 100644 --- a/cpp/src/IceUtil/Exception.cpp +++ b/cpp/src/IceUtil/Exception.cpp @@ -36,7 +36,7 @@ IceUtil::Exception::~Exception() const char* IceUtil::Exception::_name = "IceUtil::Exception"; -const string +string IceUtil::Exception::ice_name() const { return _name; @@ -94,7 +94,7 @@ IceUtil::NullHandleException::NullHandleException(const char* file, int line) : const char* IceUtil::NullHandleException::_name = "IceUtil::NullHandleException"; -const string +string IceUtil::NullHandleException::ice_name() const { return _name; @@ -125,7 +125,7 @@ IceUtil::IllegalArgumentException::IllegalArgumentException(const char* file, in const char* IceUtil::IllegalArgumentException::_name = "IceUtil::IllegalArgumentException"; -const string +string IceUtil::IllegalArgumentException::ice_name() const { return _name; diff --git a/cpp/src/IceUtil/Options.cpp b/cpp/src/IceUtil/Options.cpp index edf24c3db9a..2a93e0e5eb8 100755 --- a/cpp/src/IceUtil/Options.cpp +++ b/cpp/src/IceUtil/Options.cpp @@ -13,6 +13,72 @@ using namespace std; +IceUtil::APIException::APIException(const char* file, int line, const string& r) + : IceUtil::Exception(file, line), reason(r) +{ +} + +const char* IceUtil::APIException::_name = "IceUtil::APIException"; + +string +IceUtil::APIException::ice_name() const +{ + return _name; +} + +IceUtil::Exception* +IceUtil::APIException::ice_clone() const +{ + return new APIException(*this); +} + +void +IceUtil::APIException::ice_throw() const +{ + throw *this; +} + +ostream& +IceUtil::operator<<(ostream& out, const IceUtil::APIException& ex) +{ + ex.ice_print(out); + out << ": " << ex.reason; + return out; +} + +IceUtil::BadOptException::BadOptException(const char* file, int line, const string& r) + : IceUtil::Exception(file, line), reason(r) +{ +} + +const char* IceUtil::BadOptException::_name = "IceUtil::BadOptException"; + +string +IceUtil::BadOptException::ice_name() const +{ + return _name; +} + +IceUtil::Exception* +IceUtil::BadOptException::ice_clone() const +{ + return new BadOptException(*this); +} + +void +IceUtil::BadOptException::ice_throw() const +{ + throw *this; +} + +ostream& +IceUtil::operator<<(ostream& out, const IceUtil::BadOptException& ex) +{ + ex.ice_print(out); + out << ": " << ex.reason; + return out; +} + IceUtil::Options::Options() : parseCalled(false) { @@ -23,7 +89,7 @@ IceUtil::Options::checkArgs(const string& shortOpt, const string& longOpt, bool { if(shortOpt.empty() && longOpt.empty()) { - throw APIError("short and long option cannot both be empty"); + throw IllegalArgumentException(__FILE__, __LINE__, "short and long option cannot both be empty"); } if(!shortOpt.empty()) @@ -33,21 +99,21 @@ IceUtil::Options::checkArgs(const string& shortOpt, const string& longOpt, bool string err = "`"; err += shortOpt; err += "': a short option cannot specify more than one option"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } if(shortOpt.find_first_of(" \t\n\r\f\v") != string::npos) { string err = "`"; err += shortOpt; err += "': a short option cannot be whitespace"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } if(shortOpt[0] == '-') { string err = "`"; err += shortOpt; err += "': a short option cannot be `-'"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } } @@ -58,20 +124,21 @@ IceUtil::Options::checkArgs(const string& shortOpt, const string& longOpt, bool string err = "`"; err += longOpt; err += "': a long option cannot contain whitespace"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } if(longOpt[0] == '-') { string err = "`"; err += longOpt; err += "': a long option must not contain a leading `-'"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } } if(!needArg && !dflt.empty()) { - throw APIError("a default value can be specified only for options requiring an argument"); + throw IllegalArgumentException(__FILE__, __LINE__, + "a default value can be specified only for options requiring an argument"); } } @@ -82,7 +149,7 @@ IceUtil::Options::addOpt(const string& shortOpt, const string& longOpt, ArgType if(parseCalled) { - throw APIError("cannot add options after parse() was called"); + throw APIException(__FILE__, __LINE__, "cannot add options after parse() was called"); } checkArgs(shortOpt, longOpt, at == NeedArg, dflt); @@ -461,17 +528,17 @@ IceUtil::Options::split(const string& line) } case SingleQuote: { - throw BadQuote("missing closing single quote"); + throw BadOptException(__FILE__, __LINE__, "missing closing single quote"); break; } case DoubleQuote: { - throw BadQuote("missing closing double quote"); + throw BadOptException(__FILE__, __LINE__, "missing closing double quote"); break; } case ANSIQuote: { - throw BadQuote("unterminated $' quote"); + throw BadOptException(__FILE__, __LINE__, "unterminated $' quote"); break; } default: @@ -486,7 +553,7 @@ IceUtil::Options::split(const string& line) // // Parse a vector of arguments and return the non-option -// arguments as the return value. Throw BadOpt if any of the +// arguments as the return value. Throw BadOptException if any of the // options are invalid. // Note that args[0] is ignored because that is the name // of the executable. @@ -499,7 +566,7 @@ IceUtil::Options::parse(const vector<string>& args) if(parseCalled) { - throw APIError("cannot call parse() more than once on the same Option instance"); + throw APIException(__FILE__, __LINE__, "cannot call parse() more than once on the same Option instance"); } parseCalled = true; @@ -546,7 +613,7 @@ IceUtil::Options::parse(const vector<string>& args) { string err = "`--"; err += opt + ":' option cannot be repeated"; - throw BadOpt(err); + throw BadOptException(__FILE__, __LINE__, err); } seenNonRepeatableOpts.insert(seenPos, opt); string synonym = getSynonym(opt); @@ -563,7 +630,7 @@ IceUtil::Options::parse(const vector<string>& args) string err = "`"; err += args[i]; err += "': option does not take an argument"; - throw BadOpt(err); + throw BadOptException(__FILE__, __LINE__, err); } setOpt(opt, "", args[i].substr(p + 1), pos->second->repeat); argDone = true; @@ -587,7 +654,7 @@ IceUtil::Options::parse(const vector<string>& args) { string err = "`-"; err += opt + ":' option cannot be repeated"; - throw BadOpt(err); + throw BadOptException(__FILE__, __LINE__, err); } seenNonRepeatableOpts.insert(seenPos, opt); string synonym = getSynonym(opt); @@ -628,7 +695,7 @@ IceUtil::Options::parse(const vector<string>& args) } err += opt; err += "' option requires an argument"; - throw BadOpt(err); + throw BadOptException(__FILE__, __LINE__, err); } setOpt(opt, "", args[++i], pos->second->repeat); } @@ -672,7 +739,7 @@ IceUtil::Options::isSet(const string& opt) const if(!parseCalled) { - throw APIError("cannot lookup options before calling parse()"); + throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); } ValidOpts::const_iterator pos = checkOptIsValid(opt); @@ -686,7 +753,7 @@ IceUtil::Options::optArg(const string& opt) const if(!parseCalled) { - throw APIError("cannot lookup options before calling parse()"); + throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); } ValidOpts::const_iterator pos = checkOptHasArg(opt); @@ -700,7 +767,7 @@ IceUtil::Options::optArg(const string& opt) const } err += opt; err += "': is a repeating option -- use argVec() to get its arguments"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } Opts::const_iterator p = _opts.find(opt); @@ -718,7 +785,7 @@ IceUtil::Options::argVec(const string& opt) const if(!parseCalled) { - throw APIError("cannot lookup options before calling parse()"); + throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()"); } ValidOpts::const_iterator pos = checkOptHasArg(opt); @@ -731,7 +798,7 @@ IceUtil::Options::argVec(const string& opt) const err.push_back('-'); } err += opt + "': is a non-repeating option -- use optArg() to get its argument"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } ROpts::const_iterator p = _ropts.find(opt); @@ -747,14 +814,14 @@ IceUtil::Options::addValidOpt(const string& shortOpt, const string& longOpt, string err = "`"; err += shortOpt; err += "': duplicate option"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } if(!longOpt.empty() && _validOpts.find(longOpt) != _validOpts.end()) { string err = "`"; err += longOpt; err += "': duplicate option"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } ODPtr odp = new OptionDetails; @@ -794,7 +861,7 @@ IceUtil::Options::checkOpt(const string& opt, LengthType lt) } err += opt; err.push_back('\''); - throw BadOpt(err); + throw BadOptException(__FILE__, __LINE__, err); } return pos; } @@ -908,7 +975,7 @@ IceUtil::Options::checkOptIsValid(const string& opt) const string err = "`"; err += opt; err += "': invalid option"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } return pos; } @@ -926,7 +993,7 @@ IceUtil::Options::checkOptHasArg(const string& opt) const } err += opt; err += "': option does not take arguments"; - throw APIError(err); + throw IllegalArgumentException(__FILE__, __LINE__, err); } return pos; } diff --git a/cpp/src/IceUtil/RWRecMutex.cpp b/cpp/src/IceUtil/RWRecMutex.cpp index 8730ed4aeee..e5b97a38511 100644 --- a/cpp/src/IceUtil/RWRecMutex.cpp +++ b/cpp/src/IceUtil/RWRecMutex.cpp @@ -18,7 +18,7 @@ IceUtil::DeadlockException::DeadlockException(const char* file, int line) : const char* IceUtil::DeadlockException::_name = "IceUtil::DeadlockException"; -const ::std::string +::std::string IceUtil::DeadlockException::ice_name() const { return _name; diff --git a/cpp/src/IceUtil/Random.cpp b/cpp/src/IceUtil/Random.cpp index 9713b990932..e5daae8c47b 100644 --- a/cpp/src/IceUtil/Random.cpp +++ b/cpp/src/IceUtil/Random.cpp @@ -77,7 +77,7 @@ public: static RandomCleanup uuidCleanup; } -const string +string IceUtil::RandomGeneratorException::ice_name() const { return _name; diff --git a/cpp/src/IceUtil/ThreadException.cpp b/cpp/src/IceUtil/ThreadException.cpp index c89c2f679f0..f3499758ea1 100644 --- a/cpp/src/IceUtil/ThreadException.cpp +++ b/cpp/src/IceUtil/ThreadException.cpp @@ -19,7 +19,7 @@ IceUtil::ThreadSyscallException::ThreadSyscallException(const char* file, int li const char* IceUtil::ThreadSyscallException::_name = "IceUtil::ThreadSyscallException"; -const string +string IceUtil::ThreadSyscallException::ice_name() const { return _name; @@ -87,7 +87,7 @@ IceUtil::ThreadLockedException::ThreadLockedException(const char* file, int line const char* IceUtil::ThreadLockedException::_name = "IceUtil::ThreadLockedException"; -const string +string IceUtil::ThreadLockedException::ice_name() const { return _name; @@ -112,7 +112,7 @@ IceUtil::ThreadStartedException::ThreadStartedException(const char* file, int li const char* IceUtil::ThreadStartedException::_name = "IceUtil::ThreadStartedException"; -const string +string IceUtil::ThreadStartedException::ice_name() const { return _name; @@ -137,7 +137,7 @@ IceUtil::ThreadNotStartedException::ThreadNotStartedException(const char* file, const char* IceUtil::ThreadNotStartedException::_name = "IceUtil::ThreadNotStartedException"; -const string +string IceUtil::ThreadNotStartedException::ice_name() const { return _name; @@ -163,7 +163,7 @@ IceUtil::BadThreadControlException::BadThreadControlException(const char* file, const char* IceUtil::BadThreadControlException::_name = "IceUtil::BadThreadControlException"; -const string +string IceUtil::BadThreadControlException::ice_name() const { return _name; diff --git a/cpp/src/IceUtil/Unicode.cpp b/cpp/src/IceUtil/Unicode.cpp index f80bce3598a..714df03e32e 100644 --- a/cpp/src/IceUtil/Unicode.cpp +++ b/cpp/src/IceUtil/Unicode.cpp @@ -140,7 +140,7 @@ IceUtil::UTFConversionException::UTFConversionException(const char* file, int li _conversionResult(cr) {} -const string +string IceUtil::UTFConversionException::ice_name() const { return _name; |