Added exception handling when parsing invalid characters