fix string casting bug in bad character exception message