Use more fine grained exceptions on tests

issue3973
review8431002