zoukankan      html  css  js  c++  java
  • 调试技巧

    • 先估计哪里出问题并打断点,如果不知道,就只能在入口处打断点;然后运行程序一步一步调试。
    • 项目不能断点调试(如代码发布到生产环境或就是调试不了)怎么调?
    • 方法1:在关键环节输出日志,如果不知道哪里出错,日志从程序入口到结束运行情况都输出。输出信息要有效全面(打印“入参、结果、异常”等)。
    • 方法2:将估计出错的代码段copy到自己特意新建的控制台项目中,直接往里传参,然后打断点一步步调试。
    • 方法3:方法1和方法2结合。
    • 用throw;来抛出异常;throw ex;会将到现在为止的所有信息清空,认为你catch到的异常已经被处理了,只不过处理过程中又抛出新的异常,从而找不到真正的错误源。即throw ex重新抛出异常,并非转发原来的异常,而会更改包括StackTrace在内的许多异常内部信息;对于调用连很深情况,性能损耗超出想象。
    • 本人在94行人为抛出“abc”异常内容,下面分别是throwthrow ex的异常明细,很明显throw的异常内容是我想看到的
    未处理System.Exception
     HResult=-2146233088
     Message=abc
     Source=AutoFacTest
     StackTrace:
          在 AutoFacTest.TodayWriter.WriteDate() 位置 C:Users	estProgram.cs:行号 94
          在 AutoFacTest.Program.WriteDate() 位置 C:Users	estProgram.cs:行号 55
          在 AutoFacTest.Program.Main(String[] args) 位置 C:Users	estProgram.cs:行号 21
    ------------
    未处理System.Exception
     HResult=-2146233088
     Message=abc
     Source=AutoFacTest
     StackTrace:
          在 AutoFacTest.Program.WriteDate() 位置 C:Users	estProgram.cs:行号 55
          在 AutoFacTest.Program.Main(String[] args) 位置 C:Users	estProgram.cs:行号 21
    
  • 相关阅读:
    hlgoj 1766 Cubing
    Reverse Linked List
    String to Integer
    Bitwise AND of Numbers Range
    Best Time to Buy and Sell Stock III
    First Missing Positive
    Permutation Sequence
    Next Permutation
    Gray Code
    Number of Islands
  • 原文地址:https://www.cnblogs.com/anjun-xy/p/12732174.html
Copyright © 2011-2022 走看看