Determining which code line threw the exception

前端 未结 4 1302
故里飘歌
故里飘歌 2021-01-05 11:56

In dotNet a line throws an exception and is caught, how can I figure out which line in which file threw the exception? Seems relatively straightforward, but I can\'t figure

4条回答
  •  星月不相逢
    2021-01-05 12:20

    You can only do it if you have debug symbols available.

    catch(Exception ex) {
        // check the ex.StackTrace property
    }
    

    If you want to debug such a situation in VS, you'd better just check Thrown checkbox for Common Language Runtime Exceptions in Exceptions dialog located in Debug menu. The debugger will break as soon as the exception is thrown, even if it's in a try block.

提交回复
热议问题