diff --git a/src/android/meson.build b/src/android/meson.build index 39ebe198a..e79bf839f 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -8,6 +8,7 @@ kiwix_jni = custom_target('jni', 'org/kiwix/kiwixlib/JNIKiwixInt.java', 'org/kiwix/kiwixlib/JNIKiwixString.java', 'org/kiwix/kiwixlib/JNIKiwixBool.java', + 'org/kiwix/kiwixlib/JNIKiwixException.java', 'org/kiwix/kiwixlib/Pair.java'], output: ['org_kiwix_kiwixlib_JNIKiwix.h', 'org_kiwix_kiwixlib_JNIKiwixReader.h', diff --git a/src/android/org/kiwix/kiwixlib/JNIKiwixException.java b/src/android/org/kiwix/kiwixlib/JNIKiwixException.java new file mode 100644 index 000000000..dd0e2143c --- /dev/null +++ b/src/android/org/kiwix/kiwixlib/JNIKiwixException.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.kiwix.kiwixlib; + +public class JNIKiwixException extends Exception +{ + public JNIKiwixException(String message) { + super(message); + } +} diff --git a/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java b/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java index e204f9aba..e405ef0f4 100644 --- a/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java +++ b/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java @@ -20,6 +20,7 @@ package org.kiwix.kiwixlib; +import org.kiwix.kiwixlib.JNIKiwixException; import org.kiwix.kiwixlib.JNIKiwixString; import org.kiwix.kiwixlib.JNIKiwixInt; import org.kiwix.kiwixlib.JNIKiwixSearcher; @@ -109,9 +110,12 @@ public class JNIKiwixReader return searcher; } - public JNIKiwixReader(String filename) + public JNIKiwixReader(String filename) throws JNIKiwixException { nativeHandle = getNativeReader(filename); + if (nativeHandle == 0) { + throw new JNIKiwixException("Cannot open zimfile "+filename); + } } public JNIKiwixReader() {