Fixes #320

I'm not sure if I pick the right exception type. Feel free to advise me how I should improve the PR.