mirror of https://github.com/adamdruppe/arsd.git
better exception messages
This commit is contained in:
parent
46ec720067
commit
0c94c232a4
21
database.d
21
database.d
|
@ -77,14 +77,17 @@ struct Row {
|
||||||
package string[] row;
|
package string[] row;
|
||||||
package ResultSet resultSet;
|
package ResultSet resultSet;
|
||||||
|
|
||||||
string opIndex(size_t idx) {
|
string opIndex(size_t idx, string file = __FILE__, int line = __LINE__) {
|
||||||
if(idx >= row.length)
|
if(idx >= row.length)
|
||||||
throw new Exception(text("index ", idx, " is out of bounds on result"));
|
throw new Exception(text("index ", idx, " is out of bounds on result"), file, line);
|
||||||
return row[idx];
|
return row[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
string opIndex(string idx) {
|
string opIndex(string name, string file = __FILE__, int line = __LINE__) {
|
||||||
return row[resultSet.getFieldIndex(idx)];
|
auto idx = resultSet.getFieldIndex(name);
|
||||||
|
if(idx >= row.length)
|
||||||
|
throw new Exception(text("no field ", name, " in result"), file, line);
|
||||||
|
return row[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
string toString() {
|
string toString() {
|
||||||
|
@ -132,11 +135,7 @@ interface ResultSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
class DatabaseException : Exception {
|
class DatabaseException : Exception {
|
||||||
this(string msg) {
|
this(string msg, string file = __FILE__, size_t line = __LINE__) {
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
this(string msg, string file, size_t line) {
|
|
||||||
super(msg, file, line);
|
super(msg, file, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -529,9 +528,9 @@ class DataObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string opIndex(string field) {
|
string opIndex(string field, string file = __FILE__, size_t line = __LINE__) {
|
||||||
if(field !in fields)
|
if(field !in fields)
|
||||||
throw new DatabaseException("No such field in data object: " ~ field);
|
throw new DatabaseException("No such field in data object: " ~ field, file, line);
|
||||||
return fields[field];
|
return fields[field];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue