prevent double callback when error is thrown

Prevent calling the callback twice when an error is thrown inside it

Fixes  #464