orElseThrow
If a value is present, returns the value, otherwise throws NoSuchElementException.
Return
the non-null value described by this Optional
Since
10
Throws
if no value is present
If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.
A method reference to an exception constructor (with no arguments) can be used, for example: ::IllegalStateException.
Return
the value, if present.
Parameters
exceptionSupplier
the supplying function that produces an exception to be thrown.
Throws
if no value is present.