mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
helper mongo::ErrorMsg class that builds error strings. lighter weight than a StringBuilder, albeit less flexible.
This commit is contained in:
parent
990e708ead
commit
923660edbb
@ -154,5 +154,22 @@ namespace mongo {
|
||||
#endif
|
||||
}
|
||||
|
||||
NOINLINE_DECL ErrorMsg::ErrorMsg(const char *msg, char ch) {
|
||||
int l = strlen(msg);
|
||||
assert( l < 128);
|
||||
memcpy(buf, msg, l);
|
||||
char *p = buf + l;
|
||||
p[0] = ch;
|
||||
p[1] = 0;
|
||||
}
|
||||
|
||||
NOINLINE_DECL ErrorMsg::ErrorMsg(const char *msg, unsigned val) {
|
||||
int l = strlen(msg);
|
||||
assert( l < 128);
|
||||
memcpy(buf, msg, l);
|
||||
char *p = buf + l;
|
||||
sprintf(p, "%u", val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,21 @@ namespace mongo {
|
||||
int code;
|
||||
};
|
||||
|
||||
/** helper class that builds error strings. lighter weight than a StringBuilder, albeit less flexible.
|
||||
NOINLINE_DECL used in the constructor implementations as we are assuming this is a cold code path when used.
|
||||
|
||||
example:
|
||||
throw UserException(123, ErrorMsg("blah", num_val));
|
||||
*/
|
||||
class ErrorMsg {
|
||||
public:
|
||||
ErrorMsg(const char *msg, char ch);
|
||||
ErrorMsg(const char *msg, unsigned val);
|
||||
operator string() const { return buf; }
|
||||
private:
|
||||
char buf[256];
|
||||
};
|
||||
|
||||
class DBException : public std::exception {
|
||||
public:
|
||||
DBException( const ExceptionInfo& ei ) : _ei(ei) {}
|
||||
|
Loading…
Reference in New Issue
Block a user