use factory methods for exceptions

fix #40