SORU
25 Temmuz 2010, Pazar


C# özel durum hangi elde satır numarası

catch bir blok içinde, nasıl bir özel durum hangi satır numarasını alabilir miyim?

CEVAP
25 Temmuz 2010, Pazar


Eğer sadece daha fazla izleme biçimlendirilmiş yığın satır numarasını ihtiyacınız varsa İstisna olsun.StackTrace, StackTrace sınıfını kullanabilirsiniz:

try
{
    throw new Exception();
}
catch (Exception ex)
{
    // Get stack trace for the exception with source file information
    var st = new StackTrace(ex, true);
    // Get the top stack frame
    var frame = st.GetFrame(0);
    // Get the line number from the stack frame
    var line = frame.GetFileLineNumber();
}

Bu eğer bir pdb dosyası Meclisi varsa orada sadece çalışacağını unutmayın.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Matt Davis

    Matt Davis

    4 ŞUBAT 2006
  • PCDIY

    PCDIY

    16 AĞUSTOS 2013
  • sknbp

    sknbp

    16 Kasım 2006