A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
سؤال: first chance exception چیست؟
وقتی استثنایی در یک برنامه رخ میدهد، به آن یک first chance exception میگویند. این اولین شانسی است که سیستم به شما میدهد تا استثنای رخ داده را مدیریت کنید. اگر کدهای برنامه یا ابزاری (یک try/catch یا دیباگر) این اولین شانس را ندید بگیرند، یک second chance exception رخ میدهد. اینجا است که برنامه به احتمال زیاد خاتمه خواهد یافت.
مشاهدهی پیامهای A first chance exception در پنجرهی output ویژوال استودیو به این معنا است که استثنایی رخ داده، اما توسط یک استثناءگردان مدیریت شدهاست. بنابراین در اکثر موارد، موضوع خاصی نیست و میتوان از آن صرفنظر کرد.
سؤال: چگونه میتوان منشاء اصلی پیام رخدادن یک first chance exception را یافت؟
ویژوال استودیو در پنجرهی output، مدام پیام رخدادن first chance exception را نمایش میدهد؛ اما واقعا کدام قطعه از کدهای برنامه سبب بروز آن شدهاند؟ به صورت پیش فرض صفحهی نمایش استثناءها در VS.NET زمانی نمایان میشود که استثنای رخ داده، مدیریت نشده باشد. برای فعال سازی نمایش استثناهای مدیریت شده باید تنظیمات ذیل را اعمال کرد:
- به منوی Debug | Exceptions مراجعه کنید.
- گره Common Language Runtime Exceptions را باز کنید.
- سپس گروه System آنرا نیز باز کنید.
- در اینجا بر اساس نوع استثنایی که در پنجرهی output نمایش داده میشود، آن استثناء را یافته و Thrown آنرا انتخاب کنید.
اینبار اگر برنامه را اجرا کنید، دقیقا محلی که سبب بروز استثنای ArgumentOutOfRangeException شده در VS.NET گزارش داده خواهد شد.