本文整理汇总了C++中v8::TryCatch::CanContinue方法的典型用法代码示例。如果您正苦于以下问题:C++ TryCatch::CanContinue方法的具体用法?C++ TryCatch::CanContinue怎么用?C++ TryCatch::CanContinue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v8::TryCatch
的用法示例。
在下文中一共展示了TryCatch::CanContinue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ThrowIf
void CJavascriptException::ThrowIf(v8::Isolate *isolate, v8::TryCatch& try_catch)
{
if (try_catch.HasCaught() && try_catch.CanContinue())
{
v8::HandleScope handle_scope(isolate);
PyObject *type = NULL;
v8::Handle<v8::Value> obj = try_catch.Exception();
if (obj->IsObject())
{
v8::Handle<v8::Object> exc = obj->ToObject();
v8::Handle<v8::String> name = v8::String::NewFromUtf8(isolate, "name");
if (exc->Has(name))
{
v8::String::Utf8Value s(v8::Handle<v8::String>::Cast(exc->Get(name)));
for (size_t i=0; i<_countof(SupportErrors); i++)
{
if (strnicmp(SupportErrors[i].name, *s, s.length()) == 0)
{
type = SupportErrors[i].type;
}
}
}
}
throw CJavascriptException(isolate, try_catch, type);
}
}
示例2: errorMessage
void Executor::HandleV8Error (v8::TryCatch& tryCatch,
v8::Handle<v8::Value>& result) {
ISOLATE;
if (tryCatch.HasCaught()) {
// caught a V8 exception
if (! tryCatch.CanContinue()) {
// request was cancelled
TRI_GET_GLOBALS();
v8g->_canceled = true;
THROW_ARANGO_EXCEPTION(TRI_ERROR_REQUEST_CANCELED);
}
// request was not cancelled, but some other error occurred
// peek into the exception
if (tryCatch.Exception()->IsObject()) {
// cast the exception to an object
v8::Handle<v8::Array> objValue = v8::Handle<v8::Array>::Cast(tryCatch.Exception());
v8::Handle<v8::String> errorNum = TRI_V8_ASCII_STRING("errorNum");
v8::Handle<v8::String> errorMessage = TRI_V8_ASCII_STRING("errorMessage");
if (objValue->HasOwnProperty(errorNum) &&
objValue->HasOwnProperty(errorMessage)) {
v8::Handle<v8::Value> errorNumValue = objValue->Get(errorNum);
v8::Handle<v8::Value> errorMessageValue = objValue->Get(errorMessage);
// found something that looks like an ArangoError
if ((errorNumValue->IsNumber() || errorNumValue->IsNumberObject()) &&
(errorMessageValue->IsString() || errorMessageValue->IsStringObject())) {
int errorCode = static_cast<int>(TRI_ObjectToInt64(errorNumValue));
std::string const errorMessage(TRI_ObjectToString(errorMessageValue));
THROW_ARANGO_EXCEPTION_MESSAGE(errorCode, errorMessage);
}
}
// exception is no ArangoError
std::string const details(TRI_ObjectToString(tryCatch.Exception()));
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_QUERY_SCRIPT, details);
}
// we can't figure out what kind of error occured and throw a generic error
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);
}
if (result.IsEmpty()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);
}
// if we get here, no exception has been raised
}
示例3: stacktrace
/// @brief checks if a V8 exception has occurred and throws an appropriate C++
/// exception from it if so
void Executor::HandleV8Error(v8::TryCatch& tryCatch,
v8::Handle<v8::Value>& result,
arangodb::basics::StringBuffer* const buffer,
bool duringCompile) {
ISOLATE;
if (tryCatch.HasCaught()) {
// caught a V8 exception
if (!tryCatch.CanContinue()) {
// request was canceled
TRI_GET_GLOBALS();
v8g->_canceled = true;
THROW_ARANGO_EXCEPTION(TRI_ERROR_REQUEST_CANCELED);
}
// request was not canceled, but some other error occurred
// peek into the exception
if (tryCatch.Exception()->IsObject()) {
// cast the exception to an object
v8::Handle<v8::Array> objValue =
v8::Handle<v8::Array>::Cast(tryCatch.Exception());
v8::Handle<v8::String> errorNum = TRI_V8_ASCII_STRING("errorNum");
v8::Handle<v8::String> errorMessage = TRI_V8_ASCII_STRING("errorMessage");
TRI_Utf8ValueNFC stacktrace(TRI_UNKNOWN_MEM_ZONE, tryCatch.StackTrace());
if (objValue->HasOwnProperty(errorNum) &&
objValue->HasOwnProperty(errorMessage)) {
v8::Handle<v8::Value> errorNumValue = objValue->Get(errorNum);
v8::Handle<v8::Value> errorMessageValue = objValue->Get(errorMessage);
// found something that looks like an ArangoError
if ((errorNumValue->IsNumber() || errorNumValue->IsNumberObject()) &&
(errorMessageValue->IsString() ||
errorMessageValue->IsStringObject())) {
int errorCode = static_cast<int>(TRI_ObjectToInt64(errorNumValue));
std::string errorMessage(TRI_ObjectToString(errorMessageValue));
if (*stacktrace && stacktrace.length() > 0) {
errorMessage += "\nstacktrace of offending AQL function: ";
errorMessage += *stacktrace;
}
THROW_ARANGO_EXCEPTION_MESSAGE(errorCode, errorMessage);
}
}
// exception is no ArangoError
std::string details(TRI_ObjectToString(tryCatch.Exception()));
if (buffer) {
std::string script(buffer->c_str(), buffer->length());
LOG(ERR) << details << " " << script;
details += "\nSee log for more details";
}
if (*stacktrace && stacktrace.length() > 0) {
details += "\nstacktrace of offending AQL function: ";
details += *stacktrace;
}
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_QUERY_SCRIPT, details);
}
std::string msg("unknown error in scripting");
if (duringCompile) {
msg += " (during compilation)";
}
if (buffer) {
std::string script(buffer->c_str(), buffer->length());
LOG(ERR) << msg << " " << script;
msg += " See log for details";
}
// we can't figure out what kind of error occurred and throw a generic error
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, msg);
}
if (result.IsEmpty()) {
std::string msg("unknown error in scripting");
if (duringCompile) {
msg += " (during compilation)";
}
if (buffer) {
std::string script(buffer->c_str(), buffer->length());
LOG(ERR) << msg << " " << script;
msg += " See log for details";
}
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, msg);
}
// if we get here, no exception has been raised
}