Changed code to throw exceptions intead of returning an error code which...

... was hiding error details.