make the parsing engine more resilient to errors

move parsing code to a function and wrap it in a try/catch loop, save
the exception text as error string in the result