getOrThrow

Retrieves a required parameter from the context, throwing if not present.

Use this when a parameter is mandatory for your strategy or feature flag evaluation. Provides a descriptive error message indicating which parameter is missing.

Example:

class MyStrategy : FlippingStrategy {
override fun evaluate(context: FlippingExecutionContext): Boolean {
val userId: String = context.getOrThrow(ContextKeys.USER_ID)
// userId is guaranteed to be non-null here
return userId.startsWith("premium_")
}
}

Return

The value associated with the key, cast to type T

Parameters

key

The parameter key to retrieve

Throws

if the key is not present in the context