xxxxxxxxxx
enum ExceptionType : ubyte {
NOT_ZERO_ROWS, ///
STRICTLY_ONE_ROW, ///
NOT_MORE_THAN_ONE_ROW, ///
}
import std.exception;
import std.conv: to;
pure string generateBaseMessage(ExceptionType type)
{
final switch(type) {
case ExceptionType.NOT_ZERO_ROWS:
return `Zero rows affected`;
case ExceptionType.STRICTLY_ONE_ROW:
return `Strictly one row should be affected`;
case ExceptionType.NOT_MORE_THAN_ONE_ROW:
return `Not more than one row should be affected`;
}
}
class SearchException : Exception {
const ExceptionType type;
this(ExceptionType t, long rowsNum, string file = __FILE__, size_t line = __LINE__) pure {
type = t;
string msg = generateBaseMessage(type);
/*final switch(type) {
case ExceptionType.NOT_ZERO_ROWS:
msg = `Zero rows affected`;
break;
case ExceptionType.STRICTLY_ONE_ROW:
msg = `Strictly one row should be affected`;
break;
case ExceptionType.NOT_MORE_THAN_ONE_ROW:
msg = `Not more than one row should be affected`;
break;
}*/
msg ~=`, not ` ~ rowsNum.to!string;
super(msg, file, line); ///WTF? Error: constructor calls not allowed in loops or after labels
}
}