File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
src/main/java/dev/openfeature/sdk Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,12 @@ public void example(){
104104
105105 // configure a provider
106106 OpenFeatureAPI api = OpenFeatureAPI . getInstance();
107- api. setProviderAndWait(new InMemoryProvider (myFlags));
107+ try {
108+ api. setProviderAndWait(new InMemoryProvider (myFlags));
109+ } catch (Exception e) {
110+ // handle initialization failure
111+ e. printStackTrace();
112+ }
108113
109114 // create a client
110115 Client client = api. getClient();
@@ -149,7 +154,12 @@ To register a provider in a blocking manner to ensure it is ready before further
149154
150155``` java
151156 OpenFeatureAPI api = OpenFeatureAPI . getInstance();
152- api. setProviderAndWait(new MyProvider ());
157+ try {
158+ api. setProviderAndWait(new MyProvider ());
159+ } catch (Exception e) {
160+ // handle initialization failure
161+ e. printStackTrace();
162+ }
153163```
154164
155165#### Asynchronous
Original file line number Diff line number Diff line change @@ -207,7 +207,13 @@ public void setProvider(String domain, FeatureProvider provider) {
207207 }
208208
209209 /**
210- * Set the default provider and wait for initialization to finish.
210+ * Sets the default provider and waits for its initialization to complete.
211+ *
212+ * <p>Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown.
213+ * It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.
214+ *
215+ * @param provider the {@link FeatureProvider} to set as the default.
216+ * @throws OpenFeatureError if the provider fails during initialization.
211217 */
212218 public void setProviderAndWait (FeatureProvider provider ) throws OpenFeatureError {
213219 try (AutoCloseableLock __ = lock .writeLockAutoCloseable ()) {
@@ -224,8 +230,12 @@ public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError
224230 /**
225231 * Add a provider for a domain and wait for initialization to finish.
226232 *
233+ * <p>Note: If the provider fails during initialization, an {@link OpenFeatureError} will be thrown.
234+ * It is recommended to wrap this call in a try-catch block to handle potential initialization failures gracefully.
235+ *
227236 * @param domain The domain to bind the provider to.
228237 * @param provider The provider to set.
238+ * @throws OpenFeatureError if the provider fails during initialization.
229239 */
230240 public void setProviderAndWait (String domain , FeatureProvider provider ) throws OpenFeatureError {
231241 try (AutoCloseableLock __ = lock .writeLockAutoCloseable ()) {
You can’t perform that action at this time.
0 commit comments