[Lemon-commits] Peter Kovacs: Changing parameter order in except...
Lemon HG
hg at lemon.cs.elte.hu
Wed Oct 1 13:58:25 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/d901321d6555
changeset: 291:d901321d6555
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Wed Oct 01 11:58:03 2008 +0200
description:
Changing parameter order in exception classes + improvements
diffstat:
4 files changed, 82 insertions(+), 85 deletions(-)
lemon/error.h | 88 +++++++++++++++++++++++++-------------------------
lemon/graph_to_eps.h | 4 +-
lemon/lgf_reader.h | 63 +++++++++++++++++------------------
lemon/lgf_writer.h | 12 +++---
diffs (truncated from 596 to 300 lines):
diff -r f6899946c1ac -r d901321d6555 lemon/error.h
--- a/lemon/error.h Tue Sep 30 20:53:18 2008 +0200
+++ b/lemon/error.h Wed Oct 01 11:58:03 2008 +0200
@@ -41,11 +41,11 @@
///
class Exception : public std::exception {
public:
- ///\e Constructor
- Exception() {}
- ///\e Virtual destructor
+ ///Constructor
+ Exception() throw() {}
+ ///Virtual destructor
virtual ~Exception() throw() {}
- ///\e A short description of the exception
+ ///A short description of the exception
virtual const char* what() const throw() {
return "lemon::Exception";
}
@@ -64,29 +64,31 @@
public:
/// Copy constructor
- IoError(const IoError &error) {
+ IoError(const IoError &error) throw() : Exception() {
message(error._message);
file(error._file);
}
/// Constructor
- explicit IoError(const char *message) {
+ explicit IoError(const char *message) throw() {
IoError::message(message);
}
/// Constructor
- explicit IoError(const std::string &message) {
+ explicit IoError(const std::string &message) throw() {
IoError::message(message);
}
/// Constructor
- IoError(const std::string &file, const char *message) {
+ explicit IoError(const char *message,
+ const std::string &file) throw() {
IoError::message(message);
IoError::file(file);
}
/// Constructor
- IoError(const std::string &file, const std::string &message) {
+ explicit IoError(const std::string &message,
+ const std::string &file) throw() {
IoError::message(message);
IoError::file(file);
}
@@ -95,53 +97,50 @@
virtual ~IoError() throw() {}
/// Set the error message
- void message(const char *message) {
+ void message(const char *message) throw() {
try {
_message = message;
} catch (...) {}
}
/// Set the error message
- void message(const std::string& message) {
+ void message(const std::string& message) throw() {
try {
_message = message;
} catch (...) {}
}
/// Set the file name
- void file(const std::string &file) {
+ void file(const std::string &file) throw() {
try {
_file = file;
} catch (...) {}
}
/// Returns the error message
- const std::string& message() const {
+ const std::string& message() const throw() {
return _message;
}
/// \brief Returns the filename
///
- /// Returns the filename or empty string if the filename was not
- /// specified.
- const std::string& file() const {
+ /// Returns the filename or an empty string if it was not specified.
+ const std::string& file() const throw() {
return _file;
}
/// \brief Returns a short error message
///
- /// Returns a short error message which contains the message, the
- /// file name and the line number.
+ /// Returns a short error message which contains the message and the
+ /// file name.
virtual const char* what() const throw() {
try {
_what.clear();
std::ostringstream oss;
oss << "lemon:IoError" << ": ";
- oss << message();
- if (!file().empty()) {
- oss << " (";
- if (!file().empty()) oss << "with file '" << file() << "'";
- oss << ")";
+ oss << _message;
+ if (!_file.empty()) {
+ oss << " ('" << _file << "')";
}
_what = oss.str();
}
@@ -154,8 +153,8 @@
/// \brief Format error
///
- /// This class is used to indicate if an input file has wrong
- /// formatting, or a data representation is not legal.
+ /// This exception is thrown when an input file has wrong
+ /// format or a data representation is not legal.
class FormatError : public Exception {
protected:
std::string _message;
@@ -166,33 +165,35 @@
public:
/// Copy constructor
- FormatError(const FormatError &error) {
+ FormatError(const FormatError &error) throw() : Exception() {
message(error._message);
file(error._file);
line(error._line);
}
/// Constructor
- explicit FormatError(const char *message) {
+ explicit FormatError(const char *message) throw() {
FormatError::message(message);
_line = 0;
}
/// Constructor
- explicit FormatError(const std::string &message) {
+ explicit FormatError(const std::string &message) throw() {
FormatError::message(message);
_line = 0;
}
/// Constructor
- FormatError(const std::string &file, int line, const char *message) {
+ explicit FormatError(const char *message,
+ const std::string &file, int line = 0) throw() {
FormatError::message(message);
FormatError::file(file);
FormatError::line(line);
}
/// Constructor
- FormatError(const std::string &file, int line, const std::string &message) {
+ explicit FormatError(const std::string &message,
+ const std::string &file, int line = 0) throw() {
FormatError::message(message);
FormatError::file(file);
FormatError::line(line);
@@ -202,24 +203,24 @@
virtual ~FormatError() throw() {}
/// Set the line number
- void line(int line) { _line = line; }
+ void line(int line) throw() { _line = line; }
/// Set the error message
- void message(const char *message) {
+ void message(const char *message) throw() {
try {
_message = message;
} catch (...) {}
}
/// Set the error message
- void message(const std::string& message) {
+ void message(const std::string& message) throw() {
try {
_message = message;
} catch (...) {}
}
/// Set the file name
- void file(const std::string &file) {
+ void file(const std::string &file) throw() {
try {
_file = file;
} catch (...) {}
@@ -228,18 +229,17 @@
/// \brief Returns the line number
///
/// Returns the line number or zero if it was not specified.
- int line() const { return _line; }
+ int line() const throw() { return _line; }
/// Returns the error message
- const std::string& message() const {
+ const std::string& message() const throw() {
return _message;
}
/// \brief Returns the filename
///
- /// Returns the filename or empty string if the filename was not
- /// specified.
- const std::string& file() const {
+ /// Returns the filename or an empty string if it was not specified.
+ const std::string& file() const throw() {
return _file;
}
@@ -252,12 +252,12 @@
_what.clear();
std::ostringstream oss;
oss << "lemon:FormatError" << ": ";
- oss << message();
- if (!file().empty() || line() != 0) {
+ oss << _message;
+ if (!_file.empty() || _line != 0) {
oss << " (";
- if (!file().empty()) oss << "in file '" << file() << "'";
- if (!file().empty() && line() != 0) oss << " ";
- if (line() != 0) oss << "at line " << line();
+ if (!_file.empty()) oss << "in file '" << _file << "'";
+ if (!_file.empty() && _line != 0) oss << " ";
+ if (_line != 0) oss << "at line " << _line;
oss << ")";
}
_what = oss.str();
diff -r f6899946c1ac -r d901321d6555 lemon/graph_to_eps.h
--- a/lemon/graph_to_eps.h Tue Sep 30 20:53:18 2008 +0200
+++ b/lemon/graph_to_eps.h Wed Oct 01 11:58:03 2008 +0200
@@ -1170,7 +1170,7 @@
std::ostream* os = new std::ofstream(file_name);
if (!(*os)) {
delete os;
- throw IoError(file_name, "Cannot write file");
+ throw IoError("Cannot write file", file_name);
}
return GraphToEps<DefaultGraphToEpsTraits<G> >
(DefaultGraphToEpsTraits<G>(g,*os,true));
@@ -1191,7 +1191,7 @@
std::ostream* os = new std::ofstream(file_name.c_str());
if (!(*os)) {
delete os;
- throw IoError(file_name, "Cannot write file");
+ throw IoError("Cannot write file", file_name);
}
return GraphToEps<DefaultGraphToEpsTraits<G> >
(DefaultGraphToEpsTraits<G>(g,*os,true));
diff -r f6899946c1ac -r d901321d6555 lemon/lgf_reader.h
--- a/lemon/lgf_reader.h Tue Sep 30 20:53:18 2008 +0200
+++ b/lemon/lgf_reader.h Wed Oct 01 11:58:03 2008 +0200
@@ -516,7 +516,7 @@
_filename(fn), _digraph(digraph),
_use_nodes(false), _use_arcs(false),
_skip_nodes(false), _skip_arcs(false) {
- if (!(*_is)) throw IoError(fn, "Cannot open file");
+ if (!(*_is)) throw IoError("Cannot open file", fn);
}
/// \brief Constructor
@@ -528,7 +528,7 @@
_filename(fn), _digraph(digraph),
_use_nodes(false), _use_arcs(false),
_skip_nodes(false), _skip_arcs(false) {
- if (!(*_is)) throw IoError(fn, "Cannot open file");
+ if (!(*_is)) throw IoError("Cannot open file", fn);
}
/// \brief Destructor
@@ -879,7 +879,7 @@
maps.find(_node_maps[i].first);
if (jt == maps.end()) {
std::ostringstream msg;
- msg << "Map not found in file: " << _node_maps[i].first;
+ msg << "Map not found: " << _node_maps[i].first;
throw FormatError(msg.str());
}
map_index[i] = jt->second;
@@ -908,7 +908,7 @@
}
}
if (line >> std::ws >> c)
- throw FormatError("Extra character on the end of line");
+ throw FormatError("Extra character at the end of line");
More information about the Lemon-commits
mailing list