Skip to content

Commit 720c0ad

Browse files
committed
draft DbExceptionListener.cancelCurrentException()
1 parent b9912be commit 720c0ad

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

objectbox-java/src/main/java/io/objectbox/exception/DbExceptionListener.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -16,11 +16,30 @@
1616

1717
package 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
*/
2325
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+
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

Comments
 (0)