How to catch a decryption failed exception?


#1

I am encrypting the realm database. I am wondering how to do something if the encryption fails when trying to open the database. Below is my code. When it does fail, it doesn’t crash when I have the catch in, but nothing gets called in the catch statement.

RealmConfiguration config = new RealmConfiguration.Builder()
                .deleteRealmIfMigrationNeeded()
                .modules(new RealmDefaultModule())
                .encryptionKey(encryptedKey)
                .build();
        Realm.setDefaultConfiguration(config);

        try (Realm realm = Realm.getDefaultInstance()) {
            Timber.e("Realm tries opening");
        }catch (Exception e){
            //Delete Realm if fail to open
//            Realm.deleteRealm(config);
            Timber.e("Realm decryption failed. This does not get called");
        }

#2

This seems to be working, just Timber is not showing up in Logcat. If there is a better way I should be handling this, let me know.