std.utf throw exception instead of crash the program. but you still need to add try/catch everywhere. My point is: this simple code should work, instead of crash, it is supposed to leave all invalid codes untouched and just process the valid parts. Stream file = new BufferedFile("sample.txt"); foreach(char[] line; file) { string s = line.idup.tolower; }