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(){
104
104
105
105
// configure a provider
106
106
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
+ }
108
113
109
114
// create a client
110
115
Client client = api. getClient();
@@ -149,7 +154,12 @@ To register a provider in a blocking manner to ensure it is ready before further
149
154
150
155
``` java
151
156
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
+ }
153
163
```
154
164
155
165
#### Asynchronous
Original file line number Diff line number Diff line change @@ -207,7 +207,13 @@ public void setProvider(String domain, FeatureProvider provider) {
207
207
}
208
208
209
209
/**
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.
211
217
*/
212
218
public void setProviderAndWait (FeatureProvider provider ) throws OpenFeatureError {
213
219
try (AutoCloseableLock __ = lock .writeLockAutoCloseable ()) {
@@ -224,8 +230,12 @@ public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError
224
230
/**
225
231
* Add a provider for a domain and wait for initialization to finish.
226
232
*
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
+ *
227
236
* @param domain The domain to bind the provider to.
228
237
* @param provider The provider to set.
238
+ * @throws OpenFeatureError if the provider fails during initialization.
229
239
*/
230
240
public void setProviderAndWait (String domain , FeatureProvider provider ) throws OpenFeatureError {
231
241
try (AutoCloseableLock __ = lock .writeLockAutoCloseable ()) {
You can’t perform that action at this time.
0 commit comments