tryGet method
Attempts to retrieve the asset safely.
- If the asset exists, it is returned.
- If the asset does not exist, returns
null
instead of throwing, unlessorElseThrow
is provided, in which case the supplied exception will be thrown.
Example
final asset = resource.tryGet();
if (asset != null) {
print("Asset loaded successfully");
} else {
print("Asset not found");
}
Implementation
@override
Asset? tryGet([Supplier<Exception>? orElseThrow]) {
if(_asset != null) {
return _asset!;
} else if(orElseThrow != null) {
throw orElseThrow();
} else {
return null;
}
}