// It catchs all exceptions and sets system COM error info. static hresult catch_() { try { try { throw; } catch(const com::exception &B) { return B.set(); } catch(const ::cbear_berlios_de::stream::wvirtual_write &W) { //std::wostringstream O; //O << W; return create_exception().Description(base::to_stream<bstr_t>(W)).set(); } catch(const ::std::exception &S) { return create_exception(). Description(locale::cast<bstr_t>(std::string(S.what()))). set(); } } catch(...) { return hresult::e_fail; } }
/** * 指定バイト数のデータを書き込む */ void FileOutputStream::write(const u8 *src, s32 length) { if (!fp) { throw create_exception(IOException, "FilePointer open failed"); } if (length <= 0) { throw create_exception(IOException, "Write Length Error"); } if (fwrite((void*) src, (size_t) length, 1, fp) == 0) { throw create_exception(IOException, "fwrite error"); } }
jthrowable exn_create(Class* exc_class, const char* exc_message, jthrowable exc_cause) { ASSERT_RAISE_AREA; assert(hythread_is_suspend_enabled()); jthrowable exc_object = create_exception(exc_class, exc_message, exc_cause); if (exc_object == NULL) { exc_object = create_exception(exc_class, exc_message , NULL); if (exc_object == NULL) { return NULL; } init_cause(exc_object, exc_cause); } return exc_object; }
// Note: Function runs from unwindable area before exception throwing // function can be safe point & should be called with disable recursion = 1 static ManagedObject *create_lazy_exception( Class_Handle exn_class, Method_Handle exn_constr, U_8 * exn_constr_args, jvalue* vm_exn_constr_args) { assert(!hythread_is_suspend_enabled()); bool unwindable = set_unwindable(false); ManagedObject* result; if (NULL == vm_exn_constr_args) { result = class_alloc_new_object_and_run_constructor( (Class*) exn_class, (Method*) exn_constr, exn_constr_args); } else { // exception is throwing, so suspend can be enabled safely tmn_suspend_enable(); jthrowable exc_object = create_exception( (Class*) exn_class, (Method*) exn_constr, vm_exn_constr_args); if (exc_object) { result = exc_object->object; } else { result = NULL; } tmn_suspend_disable(); } set_unwindable(unwindable); exn_rethrow_if_pending(); return result; } //create_object_lazily
/** * 例外が発生していたら例外を投げる。 * 例外を取得する。 * exceptionがNULLの場合、popのみを行う。 */ void JniWrapper::throwHasException() { CALL_JNIENV(); jthrowable throwable = env->ExceptionOccurred(); if (throwable) { env->ExceptionClear(); env->DeleteLocalRef(throwable); throw create_exception(JavaMethodException, "throwHasException()"); } }
// It catchs all exceptions and sets system COM error info. static hresult catch_() { try { try { throw; } catch(com::exception const &B) { return B.set(); } catch(windows::exception const &W) { return hresult( true, hresult::facility_type::win32, hresult::code_type(static_cast<hresult::code_type::internal_type>( W.result()))); } catch(::cbear_berlios_de::stream::wvirtual_write const &W) { return create_exception().Description(base::to_stream<bstr_t>(W)).set(); } catch(::std::exception const &S) { return create_exception(). Description(locale::cast<bstr_t>(std::string(S.what()))). set(); } } catch(...) { return hresult::e_fail; } }
jthrowable create_exception(Class* exc_class, const char* exc_message, jthrowable exc_cause) { ASSERT_RAISE_AREA; assert(hythread_is_suspend_enabled()); jvalue args[3]; Method *exc_init = prepare_exc_creating(exc_class, args, exc_message, exc_cause); if (exc_init == NULL){ return NULL; } return create_exception(exc_class, exc_init, args); } // create_exception(Class *exc_class, const char *exc_message, jthrowable exc_cause)
// function is safe point & should be called in disable mode in safe enviroment ManagedObject* __stdcall get_exception_object_internal() { assert(!hythread_is_suspend_enabled()); if (NULL != p_TLS_vmthread->thread_exception.exc_object) { return p_TLS_vmthread->thread_exception.exc_object; } else if (NULL != p_TLS_vmthread->thread_exception.exc_class) { Exception* exception = (Exception*)&(p_TLS_vmthread->thread_exception); // suspend can be enabeled in safe enviroment tmn_suspend_enable(); jthrowable exc_object = create_exception(exception); tmn_suspend_disable(); return exc_object->object; } else { return NULL; } } // get_exc_object_internal
/** * 直接的なボーンインデックスを、ピックアップテーブルのインデックスに変換する */ static u8 boneIndex2pickIndex(u8 *pBonePickTable, const u8 boneIndex) { if (boneIndex == (u8) UNUSED_BONE) { return (u8) 0; } u8 index = 0; while (true) { if ((*pBonePickTable) == boneIndex) { // jclogf(" pickup(%d -> %d)", boneIndex, index); return index; } ++index; ++pBonePickTable; } // 通常、ここまで来ることはない throw create_exception(RuntimeException, "Error!!"); }
jthrowable exn_create(Exception* exception) { assert(hythread_is_suspend_enabled()); return create_exception(exception); }
zval * create_lcb_exception(long code TSRMLS_DC) { const char *str = lcb_strerror(NULL, (lcb_error_t)code); return create_exception(cb_exception_ce, str, code TSRMLS_CC); }
zval * create_pcbc_exception(const char *message, long code TSRMLS_DC) { return create_exception(cb_exception_ce, message, code TSRMLS_CC); }