Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/error-output'
Browse files Browse the repository at this point in the history
  • Loading branch information
tromo committed Jan 24, 2024
2 parents 15235f6 + 6ce029f commit 0977114
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ GTAGS
.vscode
.vscode/*
**.vscode
.vs/

# cruft from sublime text
*.sublime*
Expand Down
5 changes: 3 additions & 2 deletions src/amber_netcdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (idx >= _natoms)
throw(LOOSError(**i, "Atom index into trajectory frame is out of bounds"));
//throw(LOOSError(_filename, **i, "Atom index into trajectory frame is out of bounds"));
throw(TrajectoryError("updating group coords",_filename, "Atom index into trajectory frame is out of bounds"));
idx *= 3;
(*i)->coords(GCoord(_coord_data[idx], _coord_data[idx+1], _coord_data[idx+2]));
}
Expand All @@ -166,7 +167,7 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (idx >= _natoms)
throw(LOOSError(**i, "Atom index into trajectory frame is out of bounds"));
throw(TrajectoryError("updating group velocities", _filename, "Atom index into trajectory frame is out of bounds"));
idx *= 3;
(*i)->coords(GCoord(_velocity_data[idx], _velocity_data[idx+1], _velocity_data[idx+2]));
}
Expand Down
2 changes: 1 addition & 1 deletion src/amber_rst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace loos {
for (gi = g.begin(); gi != g.end(); ++gi) {
uint i = (*gi)->index();
if (i >= _natoms)
throw(LOOSError(**gi, "Atom index into trajectory is out of bounds"));
throw(TrajectoryError("updating group coords", _filename, "Atom index into trajectory frame is out of bounds"));
(*gi)->coords(frame[i]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/amber_traj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (idx >= _natoms)
throw(LOOSError(**i, "Atom index into trajectory is out of bounds"));
throw(TrajectoryError("updating group coords", _filename, "Atom index into trajectory frame is out of bounds"));
(*i)->coords(frame[idx]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/dcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (idx >= _natoms)
throw(LOOSError(**i, "Atom index into the trajectory frame is out of bounds"));
throw(TrajectoryError("updating group coords", _filename, "Atom index into trajectory frame is out of bounds"));
(*i)->coords(GCoord(xcrds[idx], ycrds[idx], zcrds[idx]));
}

Expand All @@ -430,7 +430,7 @@ namespace loos {
readHeader();
bool b = parseFrame();
if (!b)
throw(LOOSError("Cannot read first frame of DCD during initialization"));
throw(TrajectoryError("reading first frame of DCD during initialization"));
cached_first = true;
}

Expand Down
60 changes: 58 additions & 2 deletions src/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ namespace loos {
ss << a << std::endl << arg;
_msg = ss.str();
}
explicit LOOSError(const std::string& fname, const Atom& a, const std::string& arg) {
std::stringstream ss;
ss << "In file: " + fname << std::endl << a << std::endl << arg;
_msg = ss.str();
}

virtual ~LOOSError() throw() {};
virtual const char* what(void) const throw() { return(_msg.c_str()); }
Expand Down Expand Up @@ -220,8 +225,7 @@ namespace loos {

};




//! Errors while writing to files
class FileWriteError : public FileError {
public:
Expand All @@ -231,6 +235,58 @@ namespace loos {
};


//! Errors related to trajectory reading and writing
/**
* Most trajectory exceptions derive from this class.
*/
class TrajectoryError : public LOOSError {
protected:
std::string _operation;
std::string _filename;
int _errcode;

public:
TrajectoryError(const std::string& op) : LOOSError("Error while " + op), _operation(op) {}

TrajectoryError(const std::string& op, const std::string& fname)
: LOOSError("Error while " + op + ", " + fname),
_operation(op), _filename(fname)
{}

TrajectoryError(const std::string& op,
const std::string& fname,
const std::string& msg)
: LOOSError("Error while " + op + ", " + fname + "\n" + msg),
_operation(op),
_filename(fname)
{}

TrajectoryError(const std::string& op,
const std::string& fname,
const std::string& msg,
const int err)
: LOOSError("Error while " + op + ", " + fname + "\n" + msg),
_operation(op),
_filename(fname),
_errcode(err)
{}


//! What operation was involved (e.g. reading, writing. etc)
std::string operation() const throw() { return(_operation); }

//! File that had the problem (or "stream" if not a file)
std::string filename() const throw() { return(_filename); }

//! The error code that may have been generated
int errorCode() const { return(_errcode); }

//! Sets the error code
void errorCode(const int i) { _errcode = i; }

~TrajectoryError() throw() {}
};



};
Expand Down
2 changes: 1 addition & 1 deletion src/mdtrajtraj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (idx >= _natoms)
throw(LOOSError(**i, "Atom index into trajectory is out of bounds"));
throw(TrajectoryError("updating group coords", _filename, "Atom index into trajectory frame is out of bounds"));
(*i)->coords(frame[idx]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tinker_arc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (idx >= _natoms)
throw(LOOSError(**i, "Atom index into the trajectory frame is out of bounds"));
throw(TrajectoryError("updating group coords", _filename, "Atom index into trajectory frame is out of bounds"));
(*i)->coords(frame[idx]->coords());
}

Expand Down
4 changes: 2 additions & 2 deletions src/trr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (static_cast<uint>(idx) >= natoms())
throw(LOOSError(**i, "atom index into trajectory frame is out of range"));
throw(TrajectoryError("updating group coords", _filename, "Atom index into trajectory frame is out of bounds"));
(*i)->coords(coords_[idx]);
}

Expand All @@ -176,7 +176,7 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (static_cast<uint>(idx) >= natoms())
throw(LOOSError(**i, "atom index into trajectory frame is out of range"));
throw(TrajectoryError("updating group velocities", _filename, "Atom index into trajectory frame is out of bounds"));
(*i)->velocities(velo_[idx]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/xtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ namespace loos {
for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
uint idx = (*i)->index();
if (idx > natoms_)
throw(LOOSError(**i, "atom index into trajectory frame is out of range"));
throw(TrajectoryError("updating group coords", _filename, "Atom index into trajectory frame is out of bounds"));
(*i)->coords(coords_[idx]);
}

Expand Down

0 comments on commit 0977114

Please sign in to comment.