Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Raising and checking Java exceptions


Error handling in the Store project is not really satisfying. If the requested key cannot be found or if the retrieved value type does not match the requested type, a default value is returned. Do not even try with a Color entry. We definitely need a way to indicate that an error occurred! And what better way to indicate an error than an exception?

JNI provides the necessary API to raise an exception at the JVM level. These exceptions are the ones you can then catch in Java. They have nothing in common, neither the syntax nor the flow, with the usual C++ exceptions you can find in other programs (we will see more about them in Chapter 9, Porting Existing Libraries to Android).

In this part, we will see how to raise JNI exceptions from the native to the Java side.

Note

The resulting project is provided with this book under the name Store_Part9.