Fix error handling in bn_exp