問題描述
如果我自己生成異常,我可以在異常中包含任何信息:代碼行數和源文件名稱.像這樣:
If I generate an exception on my own, I can include any info into the exception: a number of code line and name of source file. Something like this:
throw std::exception("myFile.cpp:255");
但是未處理的異常或非我生成的異常怎么辦?
But what's with unhandled exceptions or with exceptions that were not generated by me?
推薦答案
似乎每個人都在努力改進您的代碼以在您的代碼中拋出異常,而沒有人嘗試解決您提出的實際問題.
It seems everyone is trying to improve your code to throw exceptions in your code, and no one is attempting the actual question you asked.
那是因為做不到.如果引發異常的代碼僅以二進制形式呈現(例如在 LIB 或 DLL 文件中),那么行號就消失了,并且無法將對象連接到源代碼中的一行.
Which is because it can't be done. If the code that's throwing the exception is only presented in binary form (e.g. in a LIB or DLL file), then the line number is gone, and there's no way to connect the object to to a line in the source code.
這篇關于如何知道導致異常的確切代碼行?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!