当前位置: 首页>>代码示例>>C++>>正文


C++ TryCatch::HasCaught方法代码示例

本文整理汇总了C++中TryCatch::HasCaught方法的典型用法代码示例。如果您正苦于以下问题:C++ TryCatch::HasCaught方法的具体用法?C++ TryCatch::HasCaught怎么用?C++ TryCatch::HasCaught使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TryCatch的用法示例。


在下文中一共展示了TryCatch::HasCaught方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Exception

v8::Handle<v8::String> V8::toJson(v8::Handle<v8::Value> value) {
	HandleScope scope;

	Handle<Context> context = Context::GetCurrent();
	Handle<Object> global = context->Global();

	Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
	Handle<Function> JSON_stringify = Handle<Function>::Cast(JSON->Get(String::New("stringify")));

	TryCatch exception;

	Handle<Value> argv[] = {
		value,
		v8::Null(),
		v8::String::New("\t")
	};

	if (exception.HasCaught()) {
		throw chi::Exception(chi::V8::ReportException(exception));
	}

	Handle<Value> stringified = JSON_stringify->Call(JSON_stringify, 3, argv);

	if (exception.HasCaught()) {
		throw chi::Exception(chi::V8::ReportException(exception));
	}

	return scope.Close(stringified.As<String>());
}
开发者ID:cha0s,项目名称:Worlds-Beyond,代码行数:29,代码来源:wbv8.cpp

示例2:

/* static */
void V8Runtime::bootstrap(Local<Object> global)
{
	EventEmitter::Initialize();
	krollGlobalObject = Persistent<Object>::New(Object::New());

	DEFINE_METHOD(krollGlobalObject, "log", krollLog);
	DEFINE_METHOD(krollGlobalObject, "binding", KrollBindings::getBinding);
	DEFINE_TEMPLATE(krollGlobalObject, "EventEmitter", EventEmitter::constructorTemplate);

	krollGlobalObject->Set(String::NewSymbol("runtime"), String::New("v8"));

	LOG_TIMER(TAG, "Executing kroll.js");

	TryCatch tryCatch;
	Handle<Value> result = V8Util::executeString(KrollBindings::getMainSource(), String::New("kroll.js"));

	if (tryCatch.HasCaught()) {
		V8Util::reportException(tryCatch, true);
	}
	if (!result->IsFunction()) {
		LOGF(TAG, "kroll.js result is not a function");
		V8Util::reportException(tryCatch, true);
	}

	Handle<Function> mainFunction = Handle<Function>::Cast(result);
	Local<Value> args[] = { Local<Value>::New(krollGlobalObject) };
	mainFunction->Call(global, 1, args);

	if (tryCatch.HasCaught()) {
		V8Util::reportException(tryCatch, true);
		LOGE(TAG, "Caught exception while bootstrapping Kroll");
	}
}
开发者ID:b0morris,项目名称:titanium_mobile,代码行数:34,代码来源:V8Runtime.cpp

示例3: BinaryTypes

	Handle<Object> SorrowContext::SetupInternals(int argc, const char *argv[]) {
		HandleScope scope;
		Local<FunctionTemplate> internals_template = FunctionTemplate::New();
		internals = Persistent<Object>::New(internals_template->GetFunction()->NewInstance());
		
		Local<Object> global = Context::GetCurrent()->Global();
		SET_METHOD(global, "quit",    Quit)
		SET_METHOD(global, "version", Version)
		SET_METHOD(internals, "compile", CompileScript)
        
		if (argc) {
			Local<Array> lineArgs = Array::New(argc-1);
			for (int i = 0; i +1 < argc; i++) {
				lineArgs->Set(Integer::New(i), V8_STR(argv[i+1]));
			}
			internals->Set(V8_STR("args"), lineArgs);
		} else {
			internals->Set(V8_STR("args"), Array::New());
		}

		Handle<Object> libsObject = Object::New();
		LoadNativeLibraries(libsObject);
		internals->Set(V8_STR("stdlib"), libsObject);
        
		Handle<ObjectTemplate> env = ObjectTemplate::New();
		env->SetNamedPropertyHandler(EnvGetter);
		internals->Set(V8_STR("env"), env->NewInstance());
        
		internals->Set(V8_STR("global"), global);
		
		binarytypes = new BinaryTypes(internals);
		iostreams = new IOStreams(internals);

		Filesystem::Initialize(internals);
		Extensions::Initialize(internals);
		

		TryCatch tryCatch;
		Local<Value> func = ExecuteString(V8_STR(sorrow_native), V8_STR("sorrow.js"));
		
		if (tryCatch.HasCaught()) {
			ReportException(&tryCatch);
			exit(10);
		}

		ASSERT_PIN(func->IsFunction(), "sorrow.js main function not found");
		Local<Function> f = Local<Function>::Cast(func);
		
		Local<Value> args[1] = { Local<Value>::New(internals) };
		
		f->Call(global, 1, args);
		
		if (tryCatch.HasCaught())  {
			ReportException(&tryCatch);
			exit(11);
		}

		return internals;
	} // SetupInternals
开发者ID:pablosole,项目名称:pet,代码行数:59,代码来源:sorrow.cpp

示例4: RunScript

jobject NativePlatform::RunScript(JNIEnv *_env, jobject obj, jstring scriptFile)
{
	JEnv env(_env);
	jobject res = nullptr;

	auto isolate = g_isolate;
	Isolate::Scope isolate_scope(isolate);
	HandleScope handleScope(isolate);
	auto context = isolate->GetCurrentContext();

	auto filename = ArgConverter::jstringToString(scriptFile);
	auto src = File::ReadText(filename);
	auto source = ConvertToV8String(src);

	TryCatch tc;

	Local<Script> script;
	ScriptOrigin origin(ConvertToV8String(filename));
	auto maybeScript = Script::Compile(context, source, &origin).ToLocal(&script);

	if(tc.HasCaught()) {
		throw NativeScriptException(tc, "Script " + filename + " contains compilation errors!");
	}

	if (!script.IsEmpty())
	{
		Local<Value> result;
		auto maybeResult = script->Run(context).ToLocal(&result);

		if(tc.HasCaught()) {
			throw NativeScriptException(tc, "Error running script " + filename);
		}
		if (!result.IsEmpty())
		{
			res = ConvertJsValueToJavaObject(env, result, static_cast<int>(Type::Null));
		}
		else
		{
			DEBUG_WRITE(">>runScript maybeResult is empty");
		}
	}
	else
	{
		DEBUG_WRITE(">>runScript maybeScript is empty");
	}

	return res;
}
开发者ID:slavchev,项目名称:android-runtime,代码行数:48,代码来源:NativePlatform.cpp

示例5: toJson

v8::Handle<v8::Value> toJson(v8::Handle<v8::Value> value) {
	HandleScope scope;

	Handle<Context> context = Context::GetCurrent();
	Handle<Object> global = context->Global();
	Handle<Object> JSON = global->Get(String::New("JSON"))->ToObject();
	Handle<Function> JSON_stringify = Handle<Function>::Cast(JSON->Get(String::New("stringify")));

	// JSON.stringify(values, null, '\t');
	Handle<Value> argv[] = {
		value,
		Null(),
		String::New("\t")
	};

	TryCatch exception;

	Handle<Value> stringified = JSON_stringify->Call(JSON_stringify, 3, argv);

	if (exception.HasCaught()) {
		return exception.ReThrow();
	}

	return scope.Close(stringified);
}
开发者ID:cha0s,项目名称:avocado-spi-v8,代码行数:25,代码来源:avocado-v8.cpp

示例6: requestValueWithCallbackTestOnlyFirstTime

        void JSAttributeTest::requestValueWithCallbackTestOnlyFirstTime(std::shared_ptr<JSZAttribute> &jsZAttribute, std::shared_ptr<ZCLAttribute> attributeMock,
                                                                        Callbacks &changeSignal) {
            ZDevice zDevice{createZDevice()};
            std::stringstream stream;
            stream << "var f = function (){\n";
            stream << "    var log = Log();\n";
            stream << "    log.info('callback called')";
            stream << "};\n";

            stream << zAttributeVariable << "\n";
            stream << "var b = a.requestValue(f);\n";
            V8_SETUP
            jsZAttribute->initJsObjectsTemplate(isolate, global);
            jsLog->initJsObjectsTemplate(isolate, global);

            setInitExpectation(zDevice, attributeMock);

            TryCatch tryCatch;
            v8::Local<v8::Value> result = runScript(stream.str());
            if (tryCatch.HasCaught()) {
                String::Utf8Value value(tryCatch.Message()->Get());
            }
            ASSERT_THAT(result.IsEmpty(), false);
            ASSERT_THAT(result->IsUndefined(), true);

            changeSignal();

            result = runScript("");
            result = runScript("");

            ASSERT_THAT(log.empty(), false);
            Log::LogData logData = log.get();
            ASSERT_THAT(logData.msg, StrEq("callback called"));
            ASSERT_THAT(log.empty(), true);
        }
开发者ID:paoloach,项目名称:zdomus,代码行数:35,代码来源:JSAttributeTest.cpp

示例7: NativeScriptException

Local<Object> Module::LoadData(Isolate *isolate, const string& path)
{
	Local<Object> json;

	auto jsonData = File::ReadText(path);

	TryCatch tc;

	auto jsonStr = ConvertToV8String(jsonData);

	auto maybeValue = JSON::Parse(isolate, jsonStr);

	if (maybeValue.IsEmpty() || tc.HasCaught())
	{
		string errMsg = "Cannot parse JSON file " + path;
		throw NativeScriptException(tc, errMsg);
	}

	auto value = maybeValue.ToLocalChecked();

	if (!value->IsObject())
	{
		string errMsg = "JSON is not valid, file=" + path;
		throw NativeScriptException(errMsg);
	}

	json = value.As<Object>();

	return json;
}
开发者ID:PeterStaev,项目名称:android-runtime,代码行数:30,代码来源:Module.cpp

示例8: v8test_eval

bool v8test_eval()
{
    BEGINTEST();

    HandleScope handle_scope;
    Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);

    Local<Object> qmlglobal = Object::New();
    qmlglobal->Set(String::New("a"), Integer::New(1922));

    Local<Script> script = Script::Compile(String::New("eval(\"a\")"), NULL, NULL, 
                                           Handle<String>(), Script::QmlMode);
    
    TryCatch tc;
    Local<Value> result = script->Run(qmlglobal);

    VERIFY(!tc.HasCaught());
    VERIFY(result->Int32Value() == 1922);

cleanup:
    context.Dispose();

    ENDTEST();
}
开发者ID:yinyunqiao,项目名称:qtdeclarative,代码行数:25,代码来源:v8test.cpp

示例9: Event

    void Event(Pollpri * p, int revents) {
        HandleScope scope;
        PRINTF("fd = %d, epfd = %d, revents = 0x%0x\n", fd, epfd, revents);
        if(revents != EV_READ) {
            printf("fd = %d, epfd = %d, revents = 0x%0x\n", fd, epfd, revents);
            return;
        }
        
        int m = 0;
        char buf[64];
        m = lseek(fd, 0, SEEK_SET);
        PRINTF("seek(%d) %d bytes: %s\n", fd, m, strerror(errno));
        m = read(fd, &buf, 63);
        buf[m] = 0;
        PRINTF("read(%d) %d bytes (%s): %s\n", fd, m, buf, strerror(errno));

        Local<Value> emit_v = handle_->Get(String::NewSymbol("emit"));
        assert(emit_v->IsFunction());
        Local<Function> emit_f = emit_v.As<Function>();
        
        Handle<Value> argv[2];
        argv[0] = String::New("edge");
        argv[1] = String::New(buf);
        
        TryCatch tc;
        
        emit_f->Call(handle_, 2, argv);

        if(tc.HasCaught()) {
            FatalException(tc);
        }
    }
开发者ID:KiL89,项目名称:bonescript,代码行数:32,代码来源:misc.cpp

示例10: ExecuteReturnString

stdext::ustring JavaScriptContext::ExecuteReturnString(const stdext::ustring & source, const stdext::ustring & name, stdext::ustring & error)
{
	stdext::ustring resultString;
	error = wstringToUstring(L"");
	Locker locker(m_isolate); 
	Isolate::Scope isolate_scope(m_isolate);
	{
		Context::Scope contextScope(*m_ctx);
		HandleScope scope;
		Local<String> scriptSource = String::New(reinterpret_cast<const uint16_t *>(source.c_str()));
		Local<String> scriptName = String::New(reinterpret_cast<const uint16_t *>(name.c_str()));
		Local<Script> script = Script::New(scriptSource, scriptName);
		Local<Value> result;
		{
			TryCatch tryCatch;
			result = script->Run();
			if (!result.IsEmpty())
			{
				String::Value value(result);
				resultString.append(reinterpret_cast<const char16_t *>(*value));
			}

			if (tryCatch.HasCaught())
			{
				error.append(wstringToUstring(L"Error running script: "));
				error.append(name);
				error.append(wstringToUstring(L" - "));
				String::Value stackTrace(tryCatch.StackTrace());
				error.append(reinterpret_cast<const char16_t*>(*stackTrace));
			}
		}
	}

	return resultString;
}
开发者ID:LogosBible,项目名称:V8Helper,代码行数:35,代码来源:JavascriptContext.cpp

示例11: jniScope

JNIEXPORT jobject JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeEvalString
	(JNIEnv *env, jobject self, jstring source, jstring filename)
{
	ENTER_V8(V8Runtime::globalContext);
	titanium::JNIScope jniScope(env);

	Handle<Value> jsSource = TypeConverter::javaStringToJsString(env, source);
	if (jsSource.IsEmpty() || !jsSource->IsString()) {
		LOGE(TAG, "Error converting Javascript string, aborting evalString");
		return NULL;
	}

	Handle<Value> jsFilename = TypeConverter::javaStringToJsString(env, filename);

	TryCatch tryCatch;
	Handle<Script> script = Script::Compile(jsSource->ToString(), jsFilename);
	Local<Value> result = script->Run();

	if (tryCatch.HasCaught()) {
		V8Util::openJSErrorDialog(tryCatch);
		V8Util::reportException(tryCatch, true);
		return NULL;
	}

	return TypeConverter::jsValueToJavaObject(env, result);
}
开发者ID:SreenuDevireddy,项目名称:titanium_mobile,代码行数:26,代码来源:V8Runtime.cpp

示例12: jniScope

JNIEXPORT void JNICALL
Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeSetWindow
	(JNIEnv *env, jobject javaKrollWindow, jlong ptr, jobject javaWindow)
{
	ENTER_V8(V8Runtime::globalContext);
	titanium::JNIScope jniScope(env);

	Handle<Object> jsKrollWindow;
	if (ptr != 0) {
		jsKrollWindow = Persistent<Object>((Object *) ptr);
	} else {
		jsKrollWindow = TypeConverter::javaObjectToJsValue(env, javaKrollWindow)->ToObject();
	}

	Handle<Value> setWindowValue = jsKrollWindow->Get(String::New("setWindow"));
	if (!setWindowValue->IsFunction()) {
		return;
	}

	Handle<Function> setWindow = Handle<Function>::Cast(setWindowValue->ToObject());

	Handle<Value> jsWindow = TypeConverter::javaObjectToJsValue(env, javaWindow);

	TryCatch tryCatch;
	if (!jsWindow->IsNull()) {
		Handle<Value> args[] = { jsWindow };
		setWindow->Call(jsKrollWindow, 1, args);
	}

	if (tryCatch.HasCaught()) {
		V8Util::openJSErrorDialog(tryCatch);
		V8Util::reportException(tryCatch);
	}
}
开发者ID:mohdaminyuddin,项目名称:titanium_mobile,代码行数:34,代码来源:V8Object.cpp

示例13: EIO_AfterIndex

    static int EIO_AfterIndex(eio_req* req) {
        HandleScope scope;
        index_baton_t* baton = static_cast<index_baton_t*>(req->data);
        ev_unref(EV_DEFAULT_UC);
        baton->lucene->Unref();

        Handle<Value> argv[2];

        if (!baton->error.empty()) {
            argv[0] = v8::String::New(baton->error.c_str());
            argv[1] = Undefined();
        }
        else {
            argv[0] = Undefined();
            argv[1] = v8::Integer::NewFromUnsigned((uint32_t)baton->indexTime);
        }

        TryCatch tryCatch;

        baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);

        if (tryCatch.HasCaught()) {
            FatalException(tryCatch);
        }

        baton->callback.Dispose();
        delete baton->index;
        delete baton;
        return 0;
    }
开发者ID:temas,项目名称:node-lucene,代码行数:30,代码来源:clucene_bindings.cpp

示例14: jniScope

/*
 * Class:     org_appcelerator_kroll_runtime_v8_V8Runtime
 * Method:    nativeRunModule
 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_org_appcelerator_kroll_runtime_v8_V8Runtime_nativeRunModule
	(JNIEnv *env, jobject self, jstring source, jstring filename, jobject activityProxy)
{
	ENTER_V8(V8Runtime::globalContext);
	titanium::JNIScope jniScope(env);

	if (moduleObject.IsEmpty()) {
		moduleObject = Persistent<Object>::New(
			V8Runtime::krollGlobalObject->Get(String::New("Module"))->ToObject());

		runModuleFunction = Persistent<Function>::New(
			Handle<Function>::Cast(moduleObject->Get(String::New("runModule"))));
	}

	Handle<Value> jsSource = TypeConverter::javaStringToJsString(source);
	Handle<Value> jsFilename = TypeConverter::javaStringToJsString(filename);
	Handle<Value> jsActivity = TypeConverter::javaObjectToJsValue(activityProxy);

	Handle<Value> args[] = { jsSource, jsFilename, jsActivity };
	TryCatch tryCatch;

	runModuleFunction->Call(moduleObject, 3, args);

	if (tryCatch.HasCaught()) {
		V8Util::openJSErrorDialog(tryCatch);
		V8Util::reportException(tryCatch, true);
	}
}
开发者ID:EnochManohar,项目名称:titanium_mobile,代码行数:33,代码来源:V8Runtime.cpp

示例15: UserInvoke

int Interface::UserInvoke(JNIEnv *jniEnv, Handle<Object> target, int opIdx, jobjectArray jArgs, jobject *jResult) {
  HandleScope scope;
  TryCatch tryCatch;
  Operation *op = operations->addr(opIdx);
  int result = OK;
  for(int i = 0; result == OK && i < op->argCount; i++) {
      result = conv->ToV8Value(jniEnv, jniEnv->GetObjectArrayElement(jArgs, i), op->argTypes[i], &op->vArgs[i]);
  }
  if(result == OK) {
    Handle<Value> vRes;
    if(target->IsFunction() && parent == 0 && operations->getLength() == 1) {
      /* invoke as function if target is a function, and interface delcares only one operation */
      vRes = (Handle<Function>::Cast(target))->Call(target, op->argCount, op->vArgs);
    } else {
      /* locate the method and invoke that */
      Handle<Value> vMethod = target->Get(op->name);
      if(!vMethod.IsEmpty() && vMethod->IsFunction()) {
        vRes = Handle<Function>::Cast(vMethod)->Call(target, op->argCount, op->vArgs);
      }
    }
    if(!vRes.IsEmpty() && op->type != TYPE_UNDEFINED) {
      jobject ob;
      result = conv->ToJavaObject(jniEnv, vRes, op->type, &ob);
      if(result == OK) {
        *jResult = ob;
      }
    }
  }
  if(tryCatch.HasCaught()) {
    result = ErrorJS;
    tryCatch.Reset();
  }
  return result;
}
开发者ID:amolmk,项目名称:anode,代码行数:34,代码来源:Interface.cpp


注:本文中的TryCatch::HasCaught方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。