Fixed a bug where the wrong exception was thrown.