Added improved error handling when string cannot be parsed

@krizon @ricbra