Time for action – raising & catching exceptions in native Store

  1. Create the Java exception com.packtpub.exception.InvalidTypeException of type Exception as follows:
    package com.packtpub.exception;
    
    public class InvalidTypeException extends Exception {
        public InvalidTypeException(String pDetailMessage) {
            super(pDetailMessage);
        }
    }

    Repeat the operation for two other exceptions: NotExistingKeyException of type Exception and StoreFullException of type RuntimeException.

  2. Open Store.java and declare thrown exceptions on getInteger() in class Store (StoreFullException is RuntimeException and does not need declaration):
    public class Store {
        ...
        public native int getInteger(String pKey)
            throws NotExistingKeyException, InvalidTypeException; public native void ...

Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.