Improve exception handling [#3232779]