From 1d49be8b99b6ab328cb45b40439705beecdce760 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 22 Apr 2024 11:05:57 +0200 Subject: [PATCH] Do not catch (and hide) exception inner exception. --- lib/src/main/cpp/libzim/archive.cpp | 37 +++++++---------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/lib/src/main/cpp/libzim/archive.cpp b/lib/src/main/cpp/libzim/archive.cpp index 92e3f92..c3b2fbc 100644 --- a/lib/src/main/cpp/libzim/archive.cpp +++ b/lib/src/main/cpp/libzim/archive.cpp @@ -88,13 +88,8 @@ JNIEXPORT void JNICALL Java_org_kiwix_libzim_Archive_setNativeArchiveByFD( int fd = jni2fd(fdObj, env); LOG("Attempting to create reader with fd: %d", fd); - try { - auto archive = std::make_shared(fd); - SET_PTR(archive); - } catch (std::exception& e) { - LOG("Error opening ZIM file"); - LOG("%s", e.what()); - } + auto archive = std::make_shared(fd); + SET_PTR(archive); #else jclass exception = env->FindClass("java/lang/UnsupportedOperationException"); env->ThrowNew(exception, "org.kiwix.libzim.Archive.setNativeArchiveByFD() is not supported under Windows"); @@ -108,13 +103,8 @@ JNIEXPORT void JNICALL Java_org_kiwix_libzim_Archive_setNativeArchiveEmbedded( int fd = jni2fd(fdObj, env); LOG("Attempting to create reader with fd: %d", fd); - try { - auto archive = std::make_shared(fd, offset, size); - SET_PTR(archive); - } catch (std::exception& e) { - LOG("Error opening ZIM file"); - LOG("%s", e.what()); - } + auto archive = std::make_shared(fd, offset, size); + SET_PTR(archive); #else jclass exception = env->FindClass("java/lang/UnsupportedOperationException"); env->ThrowNew(exception, "org.kiwix.libzim.Archive.setNativeArchiveEmbedded() is not supported under Windows"); @@ -127,14 +117,8 @@ JNIEXPORT void JNICALL Java_org_kiwix_libzim_Archive_setNativeArchiveEmbeddedFd( #ifndef _WIN32 auto fdInput = jni2fdInput(fdObj, env); - LOG("Attempting to create reader with fd: %d", fdInput); - try { - auto archive = std::make_shared(fdInput); - SET_PTR(archive); - } catch (std::exception& e) { - LOG("Error opening ZIM file"); - LOG("%s", e.what()); - } + auto archive = std::make_shared(fdInput); + SET_PTR(archive); #else jclass exception = env->FindClass("java/lang/UnsupportedOperationException"); env->ThrowNew(exception, "org.kiwix.libzim.Archive.setNativeArchiveEmbedded() is not supported under Windows"); @@ -157,13 +141,8 @@ JNIEXPORT void JNICALL Java_org_kiwix_libzim_Archive_setNativeArchiveEmbeddedFds v.push_back(fdInput); } - try { - auto archive = std::make_shared(v); - SET_PTR(archive); - } catch (std::exception& e) { - LOG("Error opening ZIM file"); - LOG("%s", e.what()); - } + auto archive = std::make_shared(v); + SET_PTR(archive); #else jclass exception = env->FindClass("java/lang/UnsupportedOperationException"); env->ThrowNew(exception, "org.kiwix.libzim.Archive.setNativeArchiveEmbedded() is not supported under Windows");