CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 1999
    Posts
    5

    What's a "First-chance exception"?

    Hi,

    I'm using the CMemoryState class to help detect memory leaks, and when running my app in debug mode using F5, the debug window occasionally says something like:

    "First-chance exception in SynClient.exe (KERNEL32.DLL): 0xC0000005: Access Violation."

    Is this actally an error? I don't actually get a normal Access Violation, so what does it mean? Is it something I should worry about and try and fix?
    And if so, how I go about working out what causes it?

    Thanks!

    Nick......


  2. #2
    Join Date
    Feb 2005
    Location
    MI
    Posts
    4

    Re: What's a "First-chance exception"?

    Usually, when I get that error, code is closing a Windows handle that has already been closed; in that case, the error is not fatal, and I perform the following steps to avoid confrontation:

    - Open the "Exceptions" menu item from the "Debug" menu and change the action for an "Invalid Handle" to "Stop if not handled."

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: What's a "First-chance exception"?

    If the exceptions are being handled then you shouldn't normally have a problem. However you should try your best to track down what's causing the exception (usually because you're doing something wrong I might add) and fix it.

    There are loads of first chance exceptions which get thrown and handled in the WMV replay code - from what I've seen - but I've not seen any adverse effects from them.

    Just be aware that it's very likely that you're doing something wrong in your code and you should try to find out what. Especially with access violation exceptions which can have potentially deadly consequences.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  4. #4
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: What's a "First-chance exception"?

    If the OS encounters an exception when running your app (well, certain types of exception anyway) it gives your application the "first chance" at handling it. If your app doesn't handle the exception, it gets passed back to the OS to see if something else will handle it.

    In my experience, first chance exceptions are rarely caused by your program. They can be caused by your program calling a DLL function which encounters an exception. Your program gets 'first chance' but it wasn't expecting the exception so it doesn't handle it. The exception then gets passed back to the DLL which possibly does handle it. Otherwise, the OS might be offered a chance to handle it. If nothing handles the exception at all, you'll get the dreaded "Unhandled Exception" message box.

    Any exceptions caused by your program will generally result in the dreaded message box - because it's quite unlikely that they'll be handled by anything else.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  5. #5
    Join Date
    Jul 2012
    Posts
    2

    Re: What's a "First-chance exception"?

    list<Pnt*>::iterator start =hex_cplist_combine->PntList_xy.begin();
    list<Pnt *>::iterator end ;


    for(start; start !=hex_cplist_combine->PntList_xy.end()
    {
    //FreePntArr();
    g_ObjRecSetup.mappingsetup.CartStarter.x = (*start)->x;
    g_ObjRecSetup.mappingsetup.CartStarter.y = (*start)->y;

    end=hex_cplist_combine->PntList_xy.begin();
    //for(end; end !=cart_cplist->PntList_xy.end()
    for(end; end !=hex_cplist_combine->PntList_xy.end()
    {


    Curve * pPolarPath, * pCartPath;
    pPolarPath = newCurve();
    pCartPath = newCurve();
    try
    {

    g_ObjRecSetup.mappingsetup.CartEnd.x= (*end)->x;
    g_ObjRecSetup.mappingsetup.CartEnd.y = (*end)->y;
    }
    catch (exception& e)
    {

    AddReportData(0,"exception caught:%s",e.what());
    }
    display();

    end++;
    }
    start++;
    }

    Above is the part of my code.I keep getting first chance exception at the line highlighted in bold.My code also crashes and I cant figure out why?The list does have values and nothing is null as far as I checked.
    Thanks
    Shweta

  6. #6
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: What's a "First-chance exception"?

    Instead of resurrecting a thread that's 7 years old (13 years from the original post) you should start a new thread with your problem.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured