1
1
/*
2
- * Copyright 2018 ObjectBox Ltd. All rights reserved.
2
+ * Copyright 2018-2020 ObjectBox Ltd. All rights reserved.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package io .objectbox .exception ;
18
18
19
+ import io .objectbox .annotation .apihint .Experimental ;
20
+
19
21
/**
20
22
* Listener for exceptions occurring during database operations.
21
23
* Set via {@link io.objectbox.BoxStore#setDbExceptionListener(DbExceptionListener)}.
22
24
*/
23
25
public 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
+
24
43
/**
25
44
* Called when an exception is thrown during a database operation.
26
45
* Do NOT throw exceptions in this method: throw exceptions are ignored (but logged to stderr).
@@ -29,3 +48,10 @@ public interface DbExceptionListener {
29
48
*/
30
49
void onDbException (Exception e );
31
50
}
51
+
52
+ /**
53
+ * Interface cannot have native methods.
54
+ */
55
+ class DbExceptionListenerJni {
56
+ native static void nativeCancelCurrentException ();
57
+ }
0 commit comments