Added exception handling for encoding problems in printDebug