Sign in to follow this  

I am confused

This topic is 4167 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get some exception error code in debug mode. "First-chance exception at 0x0055ca40 in Laby.exe: 0xC0000094: Integer division by zero." The first error is integer devision by zero. However, I explictly made my program catch all windows exception. And if I intentionally divide by zero it catchs it. Why it doesnt catch this devision by zero? And what "is exception at 0x0055ca40"? Thanks in advance.
'Laby.exe': Loaded 'E:\Projects\Engine2\V0\Laby\Debug\Laby.exe', Symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\dbghelp.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\version.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\d3d9.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\d3d8thk.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\dinput8.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\dsound.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\lpk.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\usp10.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\msctf.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\CTAGENT.DLL', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\hid.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\wintrust.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\imagehlp.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\ntmarta.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\wldap32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\samlib.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\wdmaud.drv', No symbols loaded.
'Laby.exe': Unloaded 'C:\WINDOWS\system32\wdmaud.drv'
'Laby.exe': Loaded 'C:\WINDOWS\system32\wdmaud.drv', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\msacm32.drv', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\msacm32.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\midimap.dll', No symbols loaded.
'Laby.exe': Loaded 'C:\WINDOWS\system32\ksuser.dll', No symbols loaded.
First-chance exception at 0x0055ca40 in Laby.exe: 0xC0000094: Integer division by zero.
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: WindowsError @ 0x0012e97c.
'Laby.exe': Loaded 'C:\WINDOWS\system32\psapi.dll', No symbols loaded.
'Laby.exe': Unloaded 'C:\WINDOWS\system32\psapi.dll'
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: DefaultError @ 0x0012f068.
The thread 'Win32 Thread' (0x42c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xe94) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x244) has exited with code 0 (0x0).
First-chance exception at 0x004e1ef9 in Laby.exe: 0xC0000005: Access violation reading location 0xfeeefeee.
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: WindowsError @ 0x0012d9b8.
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: WindowsError @ 0x0012d9c8.
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: WindowsError @ 0x0012d9b8.
First-chance exception at 0x0055ca40 in Laby.exe: 0xC0000094: Integer division by zero.
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: WindowsError @ 0x0012e68c.
'Laby.exe': Loaded 'C:\WINDOWS\system32\psapi.dll', No symbols loaded.
'Laby.exe': Unloaded 'C:\WINDOWS\system32\psapi.dll'
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: DefaultError @ 0x0012ed78.
First-chance exception at 0x0055ca40 in Laby.exe: 0xC0000094: Integer division by zero.
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: WindowsError @ 0x0012e68c.
'Laby.exe': Loaded 'C:\WINDOWS\system32\psapi.dll', No symbols loaded.
'Laby.exe': Unloaded 'C:\WINDOWS\system32\psapi.dll'
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: DefaultError @ 0x0012ed78.
First-chance exception at 0x0055ca40 in Laby.exe: 0xC0000094: Integer division by zero.
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: WindowsError @ 0x0012e68c.
'Laby.exe': Loaded 'C:\WINDOWS\system32\psapi.dll', No symbols loaded.
'Laby.exe': Unloaded 'C:\WINDOWS\system32\psapi.dll'
First-chance exception at 0x7c81eb33 in Laby.exe: Microsoft C++ exception: DefaultError @ 0x0012ed78.

Share this post


Link to post
Share on other sites
Ok I have read that what happens in first error exception is it checks if the program handles the exception. If not, it does second chance exception and stops the program.
If the program does handle the exception, it continues.
What I did in my program is:

static void
se_translator (unsigned int e, PEXCEPTION_POINTERS p)
{
WindowsError WinErr;

WinErr.Ptr = p;
throw WinErr;
}

ErrorHandle::ErrorHandle ()
{
this->bErrorHandle = TRUE;
this->bThrowingError = FALSE;
this->ErrorPosition = 0;
this->InitialScopeErrorPosition();
_set_se_translator (se_translator);



So it should have throwed WindowsError, and since I have a try catch in my main, it should have jumped to the catch WindowsError, but it doesnt.
Why it doesnt jump to there?
Also, is there a way to create first chance exceptions to test my exception mechanisem?


Share this post


Link to post
Share on other sites
Quote:
Original post by Erzengeldeslichtes
Assuming you're using the MSVC compiler, did you use the /EHa switch? (Enable C++ Exceptions: Yes With SEH Exceptions)


Yes, I have /EHa switch.
Enable C++ Exceptions is no.
What does this mean?

Share this post


Link to post
Share on other sites
If you have /EHa in the command line, but Enable C++ Exceptions: No in Code Generation, the Command Line will override the Code Generation window, so the compiler should still make asynchronous exceptions.

Beyond that, I can't help. Try putting __try/__except around the offending peice of code, just to see if it will catch it.

And do you have a catch(...), or just a catch(WindowsErr)?

Also, make sure you don't have the /GX switch active.

Share this post


Link to post
Share on other sites
I don't think you're supposed to throw C++ exceptions from a SEH filtering function - which is supposed to filter exceptions, not translate them. Additionally, the filter function is most likely to be working in whole another context than the normal program flow, with another stack (someone please correct me if I'm wrong), so the standard C++ unwinding won't work (at least it won't do anything good).

A quick test program:

#include <windows.h>
#include <excpt.h>

class A
{
public:
~A(){
OutputDebugStr("~A()\n");
}
};

void genFault(void)
{
int *p = NULL;
*p = 17;
};

void body(void)
{
A tmp;
genFault();
};

int se_translator(unsigned int, PEXCEPTION_POINTERS)
{
throw "SomeCPPException()";

// use this instead!

// write the exception info to the log
// (including current call stack, for example)
//return EXCEPTION_CONTINUE_SEARCH;
}

void test(void)
{
__try
{
OutputDebugStr("__try\n");
body();
}
__except( se_translator(GetExceptionCode(), GetExceptionInformation()) )
{
OutputDebugStr("__except\n");
};
};


int main()
{
try
{
OutputDebugStr("try\n");
test();
}
catch(...)
{
OutputDebugStr("catch(...)\n");
};
};


Leads to infinite rethrowing of char*.

Using the commented version of the se_translator function works well.

Share this post


Link to post
Share on other sites
Quote:
Original post by deffer
I don't think you're supposed to throw C++ exceptions from a SEH filtering function - which is supposed to filter exceptions, not translate them. Additionally, the filter function is most likely to be working in whole another context than the normal program flow, with another stack (someone please correct me if I'm wrong), so the standard C++ unwinding won't work (at least it won't do anything good).

A quick test program:
*** Source Snippet Removed ***Leads to infinite rethrowing of char*.

Using the commented version of the se_translator function works well.


Actually throwing from the se_translator is something I read about in an article/tutorial at code guru or some place like that.

Share this post


Link to post
Share on other sites
Quote:
Original post by The C modest god
Actually throwing from the se_translator is something I read about in an article/tutorial at code guru or some place like that.


Care to share the source?

EDIT: I found it www.codeguru.com/Cpp/Cpp/cpp_mfc/article.php/c851.
Now I see... I though that _set_se_translator was your own function and that you were catching SEH exceptions in a standard way.

Share this post


Link to post
Share on other sites
One of the main points of the SEH filtering functions is to basically translate a Win32 exception into a C++ exception. You do need to enable SEH exceptions in the project (and make sure you enable it in both debug and release and what ever other configurations you may have). I've done it before in code. It will work just fine. Just throw an exception from the filter function that your expecting to catch (or just use the catch all elipses in the catch statement).

try
{
}
catch(...)
{
}

Share this post


Link to post
Share on other sites
I didnt find where to enable SEH in visual 2003.
But I do have EHac enabled.
Why do I need the first and not the later?
My code for handling windows exceptions is:

static void
se_translator (unsigned int e, PEXCEPTION_POINTERS p)
{
WindowsError WinErr;

WinErr.Ptr = p;
throw WinErr;
}


Share this post


Link to post
Share on other sites
Another thing I've found is that SIMD instructions do not raise floating point exceptions. If the complier is implementing you floating point code with SSE instructions they will not raise exceptions.


Also you may need to explictially turn on FP exceptions in your code with _controlfp (this is slow so should only be done in debug mode).

Edit: Actually I didn't read the OP properly I don't think these comments apply :)

Share this post


Link to post
Share on other sites

This topic is 4167 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this