Changed exception type, added tests (issue #177)