<commit_before>/*
 * Copyright 2014 Realm Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <algorithm>
#include <stdexcept>

#include <realm/util/assert.hpp>
#include <realm/unicode.hpp>
#include "utf8.hpp"

#include "util.hpp"
#include "io_realm_internal_Util.h"
#include "io_realm_internal_SharedRealm.h"
#include "shared_realm.hpp"

using namespace std;
using namespace realm;
using namespace realm::util;
using namespace realm::jni_util;

// Caching classes and constructors for boxed types.
JavaVM* g_vm;
jclass java_lang_long;
jmethodID java_lang_long_init;
jclass java_lang_float;
jmethodID java_lang_float_init;
jclass java_lang_double;
jmethodID java_lang_double_init;
jclass session_class_ref;
jmethodID session_error_handler;

void ThrowRealmFileException(JNIEnv* env, const std::string& message, realm::RealmFileException::Kind kind);

void ConvertException(JNIEnv* env, const char *file, int line)
{
    ostringstream ss;
    try {
        throw;
    }
    catch (bad_alloc& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, OutOfMemory, ss.str());
    }
    catch (CrossTableLinkTarget& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, IllegalState, ss.str());
    }
    catch (SharedGroup::BadVersion& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, BadVersion, ss.str());
    }
    catch (invalid_argument& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, IllegalArgument, ss.str());
    }
    catch (RealmFileException& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowRealmFileException(env, ss.str(), e.kind());
    }
    catch (InvalidTransactionException& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, IllegalState, ss.str());
    }
    catch (InvalidEncryptionKeyException& e) {
        ss << e.what() << " in " << file << " line " << line;<commit_msg>Add the underlying information on RealmFileException. (#3940)<commit_after>/*
 * Copyright 2014 Realm Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <algorithm>
#include <stdexcept>

#include <realm/util/assert.hpp>
#include <realm/unicode.hpp>
#include "utf8.hpp"

#include "util.hpp"
#include "io_realm_internal_Util.h"
#include "io_realm_internal_SharedRealm.h"
#include "shared_realm.hpp"

using namespace std;
using namespace realm;
using namespace realm::util;
using namespace realm::jni_util;

// Caching classes and constructors for boxed types.
JavaVM* g_vm;
jclass java_lang_long;
jmethodID java_lang_long_init;
jclass java_lang_float;
jmethodID java_lang_float_init;
jclass java_lang_double;
jmethodID java_lang_double_init;
jclass session_class_ref;
jmethodID session_error_handler;

void ThrowRealmFileException(JNIEnv* env, const std::string& message, realm::RealmFileException::Kind kind);

void ConvertException(JNIEnv* env, const char *file, int line)
{
    ostringstream ss;
    try {
        throw;
    }
    catch (bad_alloc& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, OutOfMemory, ss.str());
    }
    catch (CrossTableLinkTarget& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, IllegalState, ss.str());
    }
    catch (SharedGroup::BadVersion& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, BadVersion, ss.str());
    }
    catch (invalid_argument& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, IllegalArgument, ss.str());
    }
    catch (RealmFileException& e) {
        ss << e.what() << " (" <<  e.underlying() <<  ") in " << file << " line " << line;
        ThrowRealmFileException(env, ss.str(), e.kind());
    }
    catch (InvalidTransactionException& e) {
        ss << e.what() << " in " << file << " line " << line;
        ThrowException(env, IllegalState, ss.str());
    }
    catch (InvalidEncryptionKeyException& e) {
        ss << e.what() << " in " << file << " line " << line;
{'fraction_non_alphanumeric': 0.13362814843299364, 'fraction_numerical': 0.004229955777735051, 'mean_word_length': 3.4922279792746114, 'pattern_counts': {'":': 0, '<': 155, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6259149', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1604, 'n_words': 484}