Improve exception handling. Add more tests for error conditions. Bump version to 1.4.0.