improve exception handling, add test for custom exception