Factory method for parsing literals with exception handling.