passing errors to callback when present

Here I propose one possible solution for #2272.
If you agree with it, I can make another commit using a common function to test for the presence of a callback and throwing the error to be used at the begin of every function, also uniforming the behavior through all of them.