Template tryCall
Creates a range expression out of a throwing functions
template tryCall(alias func)
;
Contained Functions
Name | Description |
---|---|
tryCall |
Parameters
Name | Description |
---|---|
func | the function to bind to |
args | the arguments to pass through to func |
See Also
ddash
Returns
A ddash
object bound to the function that can be called with args
Since
- 0.8.0
Example
import std .typecons: Flag;
void f0(Flag!"throws" throws) {
if (throws) {
throw new Exception("f0");
}
}
int f1(Flag!"throws" throws) {
if (throws) {
throw new Exception("f1");
}
return 0;
}
auto f0_throws = tryCall!f0(Yes .throws);
auto f0_nothrows = tryCall!f0(No .throws);
auto f1_throws = tryCall!f1(Yes .throws);
auto f1_nothrows = tryCall!f1(No .throws);
auto g() {
try {
throw new Exception("hahah");
} catch (Exception ex) {
return ex;
}
}
assert(!f0_throws .isSuccess);
assert( f0_nothrows .isSuccess);
assert(!f1_throws .isSuccess);
assert( f1_nothrows .isSuccess);