Add exception throwing in error cases.

Signed-off-by: Nigel Magnay <nigel.magnay@gmail.com>