Catch explicit exceptions when setting locale

Follow on to #2386.  @pelson