11/*
2- * Copyright 2018 ObjectBox Ltd. All rights reserved.
2+ * Copyright 2018-2020 ObjectBox Ltd. All rights reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package io .objectbox .exception ;
1818
19+ import io .objectbox .annotation .apihint .Experimental ;
20+
1921/**
2022 * Listener for exceptions occurring during database operations.
2123 * Set via {@link io.objectbox.BoxStore#setDbExceptionListener(DbExceptionListener)}.
2224 */
2325public interface DbExceptionListener {
26+ /**
27+ * WARNING/DISCLAIMER: Please avoid this method and handle exceptions "properly" instead.
28+ * By using this method, you "hack" into the exception handling by preventing native core exceptions to be
29+ * raised in Java. This typically results in methods returning zero or null regardless if this breaks any
30+ * non-zero or non-null contract that would be in place otherwise. Additionally, "canceling" exceptions
31+ * may lead to unforeseen follow-up errors that would never occur otherwise. In short, by using this method
32+ * you are accepting undefined behavior.
33+ * <p>
34+ * Also note that it is likely that this method will never graduate from @{@link Experimental} until it is removed.
35+ * <p>
36+ * This method may be only called from {@link #onDbException(Exception)}.
37+ */
38+ @ Experimental
39+ static void cancelCurrentException () {
40+ DbExceptionListenerJni .nativeCancelCurrentException ();
41+ }
42+
2443 /**
2544 * Called when an exception is thrown during a database operation.
2645 * Do NOT throw exceptions in this method: throw exceptions are ignored (but logged to stderr).
@@ -29,3 +48,10 @@ public interface DbExceptionListener {
2948 */
3049 void onDbException (Exception e );
3150}
51+
52+ /**
53+ * Interface cannot have native methods.
54+ */
55+ class DbExceptionListenerJni {
56+ native static void nativeCancelCurrentException ();
57+ }
0 commit comments