本文整理汇总了C++中ExceptionRef类的典型用法代码示例。如果您正苦于以下问题:C++ ExceptionRef类的具体用法?C++ ExceptionRef怎么用?C++ ExceptionRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExceptionRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getConfigManager
bool NodeConfigManager::getBitmunkHomePath(string& path)
{
bool rval;
Config c = getConfigManager()->getConfig(MAIN_ID);
// get initial value
const char* bitmunkHomePath = c["monarch.app.Core"]["home"]->getString();
// make sure bitmunkHomePath is user-expanded
rval = File::expandUser(bitmunkHomePath, path);
// make sure path is absolute
if(!rval || !File::isPathAbsolute(path.c_str()))
{
ExceptionRef e = new Exception(
"Could not get absolute bitmunk home path.",
"bitmunk.node.NodeConfigManager.ConfigError");
e->getDetails()["bitmunkHomePath"] = bitmunkHomePath;
Exception::push(e);
rval = false;
}
#ifdef WIN32
if(rval)
{
// swap backslashes to standard if on windows
StringTools::replaceAll(path, "\\", "/");
}
#endif
return rval;
}
示例2: fread
int FileInputStream::read(char* b, int length)
{
int rval = -1;
if(ensureOpen())
{
rval = 0;
// do read
int count = fread(b, 1, length, mHandle);
if(count != length)
{
// check for an error
if(ferror(mHandle) != 0)
{
ExceptionRef e = new Exception(
"Could not read file.",
"monarch.io.File.ReadError");
e->getDetails()["path"] = mFile->getAbsolutePath();
e->getDetails()["error"] = strerror(errno);
Exception::set(e);
rval = -1;
}
}
if(rval != -1)
{
// return number of bytes read
rval = count;
}
}
return rval;
}
示例3: Exception
int64_t MySqlRow::getColumnIndex(const char* name)
{
// use 64-bit signed int to cover all values + error (negative 1)
int64_t rval = -1;
for(unsigned int i = 0; i < mFieldCount; ++i)
{
if(strcmp(name, mFields[i].name) == 0)
{
rval = i;
break;
}
}
if(rval == -1)
{
// set exception
ExceptionRef e = new Exception(
"Could not get column value. Invalid column name.",
"monarch.sql.mysql.MySql");
e->getDetails()["name"] = name;
Exception::set(e);
}
return rval;
}
示例4: stop
bool PortService::start()
{
if(!mOperation.isNull())
{
// stop service
stop();
}
// initialize service
mOperation = initialize();
if(!mOperation.isNull())
{
// run service
mServer->getOperationRunner()->runOperation(mOperation);
}
else
{
// set exception
ExceptionRef e = new Exception(
"Port service failed to start.",
"monarch.net.PortService.StartFailed");
e->getDetails()["name"] = mName;
Exception::push(e);
// clean up service
cleanup();
}
return !mOperation.isNull();
}
示例5: rval
Config NodeConfigManager::getModuleConfig(const char* moduleName, bool raw)
{
Config rval(NULL);
if(raw)
{
rval = getConfigManager()->getConfig(moduleName, raw);
}
else
{
Config tmp = getConfigManager()->getConfig(MAIN_ID, raw);
if(!tmp.isNull() && tmp->hasMember(moduleName))
{
rval = tmp[moduleName];
}
else
{
ExceptionRef e = new Exception(
"Could not get module config. Invalid module name.",
"bitmunk.node.NodeConfigManager.InvalidModuleName");
e->getDetails()["moduleName"] = moduleName;
Exception::push(e);
}
}
return rval;
}
示例6: getPath
DynamicObject ValidatorContext::addError(
const char* type, DynamicObject* object)
{
DynamicObject errorDetail;
// setup error detail
errorDetail["type"] = type;
// FIXME: localize message -- lehn
// FIXME: really? do we need to mention this, because we'd have to
// do this for every string in the system.. -- manu
errorDetail["message"] = "The given value does not meet all of the data "
"validation requirements. Please examine the error details for more "
"information about the specific requirements.";
if(object != NULL && (mMaskType & ValidatorContext::MaskInvalidValues) == 0)
{
errorDetail["invalidValue"] = *object;
}
// add error detail to results errors
std::string fullpath = getPath();
mResults["errors"][fullpath.c_str()] = errorDetail;
// Skip setting exceptions if requested. Return errorDetail regardless.
if(mSetExceptions)
{
ExceptionRef e;
if(!Exception::isSet())
{
e = new Exception(
"The given object does not meet all of the data validation "
"requirements. Please examine the error details for more "
"information about the specific requirements.",
"monarch.validation.ValidationError");
Exception::set(e);
}
else
{
e = Exception::get();
// Check if we are adding to a ValidationError
if(!e->isType("monarch.validation.ValidationError"))
{
// FIXME: this is a bit bogus. If validation checking keeps causing
// other exceptions then a long cause chain could be generated
// switching between ValidationError and other types.
e = new Exception(
"The given object does not meet all of the data validation "
"requirements. Please examine the error details for more "
"information about the specific requirements.",
"monarch.validation.ValidationError");
Exception::push(e);
}
}
// add detail to "errors" section of exception details
e->getDetails()["errors"][fullpath.c_str()] = errorDetail;
}
return errorDetail;
}
示例7: Exception
bool AbstractSocket::listen(int backlog)
{
if(!isBound())
{
ExceptionRef e = new Exception(
"Cannot listen on unbound socket.",
SOCKET_EXCEPTION_TYPE ".NotBound");
Exception::set(e);
}
else
{
// set backlog
mBacklog = backlog;
// listen
int error = SOCKET_MACRO_listen(mFileDescriptor, backlog);
if(error < 0)
{
ExceptionRef e = new Exception(
"Could not listen on socket.", SOCKET_EXCEPTION_TYPE);
e->getDetails()["error"] = strerror(errno);
Exception::set(e);
}
else
{
// now listening
mListening = true;
// set socket to non-blocking so accept() calls can be interrupted
SOCKET_MACRO_fcntl(mFileDescriptor, F_SETFL, O_NONBLOCK);
}
}
return mListening;
}
示例8: Exception
bool SessionManager::getSessionFromAction(
BtpAction* action, string& session, InternetAddress* ip)
{
bool rval = true;
// get client cookies
CookieJar jar;
jar.readCookies(action->getRequest()->getHeader(), CookieJar::Client);
// check for bitmunk-session cookie
Cookie cookie = jar.getCookie("bitmunk-session");
if(cookie.isNull())
{
ExceptionRef e = new Exception(
"No 'bitmunk-session' cookie.",
"bitmunk.webui.SessionManager.MissingCookie");
e->getDetails()["missingCookie"] = "bitmunk-session";
Exception::set(e);
rval = false;
}
else
{
// get session ID
session = cookie["value"]->getString();
}
if(rval)
{
// get IP
rval = action->getClientInternetAddress(ip);
}
return rval;
}
示例9: BM_USER_ID
bool SessionManager::checkAccessControl(
const char* username, InternetAddress* ip)
{
bool rval;
// check the address against 127.x.x.x for localhost status, any user
// has access control from localhost
rval = (strncmp(ip->getAddress(), "127.", 4) == 0);
if(!rval)
{
// not localhost, will have to check session database:
// get bitmunk user ID
Url url;
url.format("/api/3.0/users?username=%s", username);
DynamicObject user;
if(mNode->getMessenger()->getFromBitmunk(&url, user))
{
rval = mSessionDatabase.checkAccessControl(
BM_USER_ID(user["id"]), ip->getAddress());
}
}
if(!rval)
{
ExceptionRef e = new Exception(
"Access denied for user.",
"bitmunk.webui.SessionManager.AccessDenied");
e->getDetails()["username"] = username;
e->getDetails()["ip"] = ip->getAddress();
Exception::push(e);
}
return rval;
}
示例10: _compileDomainRegex
static PatternRef _compileDomainRegex(const char* domain)
{
PatternRef rval(NULL);
string regex = "^";
regex.append(domain);
regex.append("$");
// escape all periods
StringTools::replaceAll(regex, ".", "\\.");
// replace all wildcards with (.*)
StringTools::replaceAll(regex, "*", ".*");
// try to compile the pattern (match case, no-sub matches allowed)
rval = Pattern::compile(regex.c_str(), true, false);
if(rval.isNull())
{
ExceptionRef e = new Exception(
"Could not add proxy domain. Invalid domain format.",
"bitmunk.node.ProxyResourceHandler.InvalidDomainFormat");
e->getDetails()["domain"] = domain;
e->getDetails()["regex"] = regex.c_str();
Exception::push(e);
}
return rval;
}
示例11: pthread_once
void Thread::setException(ExceptionRef& e, bool caused)
{
// initialize threads
pthread_once(&sThreadsInit, &initializeThreads);
// get the exception reference for the current thread
ExceptionRef* ref =
static_cast<ExceptionRef*>(pthread_getspecific(sExceptionKey));
if(ref == NULL)
{
// create the exception reference
ref = new ExceptionRef(NULL);
*ref = e;
pthread_setspecific(sExceptionKey, ref);
}
else
{
if(caused && !e.isNull())
{
// set cause of passed exception to previous exception
e->setCause(*ref);
}
// update the reference
*ref = e;
}
}
示例12: Exception
bool ControlPoint::performAction(
const char* actionName, DynamicObject& params,
Service& service, ActionResult& result)
{
bool rval = false;
// ensure action exists in the service
if(!service->hasMember("actions") ||
!service["actions"]->hasMember(actionName))
{
ExceptionRef e = new Exception(
"Service has no such action.",
"monarch.upnp.NoSuchAction");
e->getDetails()["actionName"] = actionName;
e->getDetails()["serviceType"] = service["serviceType"]->getString();
e->getDetails()["serviceId"] = service["serviceId"]->getString();
Exception::set(e);
}
else
{
// create a soap message
SoapMessage msg;
msg["name"] = actionName;
msg["namespace"] = service["serviceType"]->getString();
msg["params"] = params;
// do soap transfer
rval = doSoap(service, msg, result);
}
return rval;
}
示例13: Url
bool AbstractConnection::connect(const char* url)
{
bool rval = false;
// clean up old url
mUrl.setNull();
// ensure URL isn't malformed
Exception::clear();
mUrl = new Url(url);
if(Exception::isSet())
{
ExceptionRef e = new Exception(
"Invalid database url.",
"monarch.sql.Connection.InvalidUrl");
e->getDetails()["url"] = url;
Exception::push(e);
}
else
{
// call implementation-specific code
rval = connect(&(*mUrl));
}
return rval;
}
示例14: prepare
bool AbstractConnection::rollback()
{
bool rval = false;
// save the reason for the rollback
ExceptionRef reason = Exception::get();
// attempt to do the rollback
Statement* s = prepare("ROLLBACK");
rval = (s != NULL) && s->execute() && s->reset();
if(!rval)
{
ExceptionRef e = new Exception(
"Could not rollback transaction.",
"monarch.sql.Connection.TransactionRollbackError");
if(!reason.isNull())
{
e->getDetails()["rollbackReason"] =
Exception::convertToDynamicObject(reason);
}
Exception::push(e);
}
return rval;
}
示例15: snprintf
bool DirectiveService::createDirective(
BtpAction* action, DynamicObject& in, DynamicObject& out)
{
bool rval = false;
UserId userId;
if(mNode->checkLogin(action, &userId))
{
// turn user ID into a key
char key[22];
snprintf(key, 22, "%" PRIu64, userId);
// lock to insert directive
mCacheLock.lock();
{
// initialize user's directive cache as needed
if(!mDirectives->hasMember(key))
{
mDirectives[key]->setType(Map);
}
DynamicObject& cache = mDirectives[key];
if(cache->length() < MAX_DIRECTIVES)
{
// insert directive into cache
insertDirective(cache, in);
// return directive ID
out["directiveId"] = in["id"]->getString();
rval = true;
// fire created event
Event e;
e["type"] = "bitmunk.system.Directive.created";
e["details"]["userId"] = userId;
e["details"]["directiveId"] = in["id"];
e["details"]["directive"] = in;
mNode->getEventController()->schedule(e);
}
else
{
// too many directives
ExceptionRef e = new Exception(
"Could not add directive. Maximum number of "
"directives reached.",
"bitmunk.system.DirectiveService.TooManyDirectives");
e->getDetails()["userId"] = userId;
e->getDetails()["max"] = MAX_DIRECTIVES;
Exception::set(e);
}
}
mCacheLock.unlock();
}
return rval;
}