Backport exception changes from master