Fix throwing proper exception on error