It sounds like what you're trying to do is have a function
f
depend on the behaviour of its caller g
. That at the very least sounds like a bad thing, because now f
is more complex and that means harder to understand, test and change. There are probably better explanations of why to avoid this sort of thing - the kind of phrase to search for is "high level modules depend on low level modules" (and not the other way round - here f
is the lower level one). You can probably find a better design, which may just be letting the caller handle the failures that the function can't handle.