Add exceptions

Throw an exception for most error conditions instead of returning nothing.