NXBT-758: better manage boder cases (NPE and so on); do not overwrite output file in case of error