किसी दिए गए अपवाद के लिए स्टैकट्रेस देखने के लिए, का उपयोग e.StackTrace
आप अधिक विस्तृत जानकारी की जरूरत है, तो आप System.Diagnostics.StackTrace वर्ग का उपयोग कर सकते हैं (यहाँ कुछ कोड आप का प्रयास करने के लिए है):
try
{
throw new Exception();
}
catch (Exception ex)
{
//Get a StackTrace object for the exception
StackTrace st = new StackTrace(ex, true);
//Get the first stack frame
StackFrame frame = st.GetFrame(0);
//Get the file name
string fileName = frame.GetFileName();
//Get the method name
string methodName = frame.GetMethod().Name;
//Get the line number from the stack frame
int line = frame.GetFileLineNumber();
//Get the column number
int col = frame.GetFileColumnNumber();
}
यह केवल तभी काम करेगा जब असेंबली के लिए कोई पीडीबी फ़ाइल उपलब्ध हो। प्रोजेक्ट गुण देखें - टैब बनाएं - उन्नत - डीबग जानकारी चयन यह सुनिश्चित करने के लिए कि कोई पीडीबी फ़ाइल है।
स्रोत
2010-08-06 17:42:13
यह कोड भी संकलित कैसे करता है? –
यह मैंने इसे उदाहरण के रूप में दिखाने के लिए नहीं बनाया है – Crash893
संभावित डुप्लिकेट http://stackoverflow.com/questions/8338495/how-to-get-error-line-number-of-code-using-try-catch –