Fix bug in exception wrapping