<commit_before>#include "../../../../vowpalwabbit/parser.h"
#include "../../../../vowpalwabbit/vw.h"
#include "vw_VW.h"

void throw_java_exception(JNIEnv *env, const char* name, const char* msg) {
     jclass jc = env->FindClass(name);
     if (jc)
        env->ThrowNew (jc, msg);
}

void rethrow_cpp_exception_as_java_exception(JNIEnv *env) {
    try {
        throw;
    }
    catch(const std::bad_alloc& e) {
        throw_java_exception(env, "java/lang/OutOfMemoryError", e.what());
    }
    catch(const std::ios_base::failure& e) {
        throw_java_exception(env, "java/io/IOException", e.what());
    }
    catch(const std::exception& e) {
        const char* what = e.what();
        // It would appear that this text has changed between different boost variants
        std::string prefix1("unrecognised option");
        std::string prefix2("unknown option");

        if (std::string(what).substr(0, prefix1.size()) == prefix1 ||
            std::string(what).substr(0, prefix2.size()) == prefix2)
            throw_java_exception(env, "java/lang/IllegalArgumentException", what);
        else
            throw_java_exception(env, "java/lang/Exception", what);
    }
    catch (...) {
        throw_java_exception(env, "java/lang/Error", "Unidentified exception => "
                                   "rethrow_cpp_exception_as_java_exception "
                                   "may require some completion...");
    }
}

vw* getVW(jlong vwPtr) {
    return (vw*) vwPtr;
}

JNIEXPORT jlong JNICALL Java_vw_VW_initialize(JNIEnv *env, jobject obj, jstring command) {
    jlong vwPtr = 0;
    try {
        vwPtr = (jlong) VW::initialize(env->GetStringUTFChars(command, NULL));
    }
    catch(...) {<commit_msg>Getting all Java tests to pass in Travis<commit_after>#include "../../../../vowpalwabbit/parser.h"
#include "../../../../vowpalwabbit/vw.h"
#include "vw_VW.h"

void throw_java_exception(JNIEnv *env, const char* name, const char* msg) {
     jclass jc = env->FindClass(name);
     if (jc)
        env->ThrowNew (jc, msg);
}

void rethrow_cpp_exception_as_java_exception(JNIEnv *env) {
    try {
        throw;
    }
    catch(const std::bad_alloc& e) {
        throw_java_exception(env, "java/lang/OutOfMemoryError", e.what());
    }
    catch(const std::ios_base::failure& e) {
        throw_java_exception(env, "java/io/IOException", e.what());
    }
    catch(const std::exception& e) {
        const char* what = e.what();
        // It would appear that this text has changed between different boost variants
        std::string prefix1("unrecognised option");
        std::string prefix2("unknown option");

        std::cout << what << std::endl;

        if (std::string(what).substr(0, prefix1.size()) == prefix1 ||
            std::string(what).substr(0, prefix2.size()) == prefix2)
            throw_java_exception(env, "java/lang/IllegalArgumentException", what);
        else
            throw_java_exception(env, "java/lang/Exception", what);
    }
    catch (...) {
        throw_java_exception(env, "java/lang/Error", "Unidentified exception => "
                                   "rethrow_cpp_exception_as_java_exception "
                                   "may require some completion...");
    }
}

vw* getVW(jlong vwPtr) {
    return (vw*) vwPtr;
}

JNIEXPORT jlong JNICALL Java_vw_VW_initialize(JNIEnv *env, jobject obj, jstring command) {
    jlong vwPtr = 0;
    try {
        vwPtr = (jlong) VW::initialize(env->GetStringUTFChars(command, NULL));
    }
    catch(...) {
{'fraction_non_alphanumeric': 0.146875, 'fraction_numerical': 0.005113636363636364, 'mean_word_length': 2.578252032520325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4196686', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1125, 'n_words': 236}