7
Benim C# (4.0) asp.net web uygulamasında meydana gelen bir özel durumdan ayrıntıları almaya çalışıyorum. Bin klasöründe .pdb dosyası var.Kaynak dosya, yöntem ve satır istisnası alın
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//throwing Exception
using (SqlConnection connection=new SqlConnection(""))
{
connection.Open();
}
}
catch (Exception exception)
{
//Get a StackTrace object for the exception
StackTrace st = new StackTrace(exception, true);
//Get the first stack frame
StackFrame frame = st.GetFrame(0); //returns {PermissionDemand at offset 5316022 in file:line:column <filename unknown>:0:0}
//Get the file name
string fileName = frame.GetFileName(); //returns null
//Get the method name
string methodName = frame.GetMethod().Name; //returns PermissionDemand
//Get the line number from the stack frame
int line = frame.GetFileLineNumber(); //returns 0
//Get the column number
int col = frame.GetFileColumnNumber(); //returns 0
}
}
burada yanlış nedir? - Aşağıdaki kod beklendiği gibi çalışmıyor?
güncelleme: "StackFrame çerçevesi = st.GetFrame (st.FrameCount - 1);" bu sorunu çözmüştür.
exception.StackTrace yardımcı olur mu? (http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx) – Samuel
Bu, tüm hata dizesini size döndürüyor. Bunu istemiyorum. –
Yayınınız "Bir istisnayla ilgili ayrıntıları almaya çalışıyorum" ile başlar. StackTrace özelliği, yığın izlemenin bir dize temsilini döndürür. Tüm hata dizesini döndürmez. Bu exception.ToString() tarafından oluşturulacaktı. Lütfen daha spesifik olunuz – Samuel