public static string SerializeDTO(DTO dto) { try { XmlSerializer xmlSer = new XmlSerializer(dto.GetType()); StringWriter sWriter = new StringWriter(); xmlSer.Serialize(sWriter, dto); return sWriter.ToString(); } catch(Exception ex) { throw ex; }}
public static string SerializeDTO(DTO dto) { XmlSerializer xmlSer = new XmlSerializer(dto.GetType()); StringWriter sWriter = new StringWriter(); xmlSer.Serialize(sWriter, dto); return sWriter.ToString();}
编辑:
不要
try { // Do stuff that might throw an exception}catch (Exception e) { throw e; // This destroys the strack trace information!}
做
try { // Do stuff that might throw an exception}catch (SqlException e) { // Log it if (e.ErrorCode != NO_ROW_ERROR) { // filter out NoDataFound. // Do special cleanup, like maybe closing the "dirty" database connection. throw; // This preserves the stack trace }}catch (IOException e) { // Log it throw;}catch (Exception e) { // Log it throw new DAOException("Excrement occurred", e); // wrapped & chained exceptions (just like java).}finally { // Normal clean goes here (like closing open files).}
参考资料:
弑天下
慕桂英4014372
小怪兽爱吃肉
相关分类