Solved

evc++ /EHa option cause error LNK2019

Posted on 2011-09-29
14
602 Views
Last Modified: 2012-06-27
Hi,

i,m trying to use /EHa option in evc++ to use a TRY CATCH block catching also asyncrounouns errors (like index out of bound etc...)

the problem is that while linking it gives me this error:

DiagTool.obj : error LNK2019: unresolved external symbol ___CxxLongjmpUnwind@4 referenced in function "public: virtual int __thiscall CDiagToolApp::InitInstance(void)" (?InitInstance@CDiagToolApp@@UAEHXZ)

Project otpions are:

/nologo /W3 /Zi /Od /I "..\jpeglib\\" /D "DEBUG" /D "_i386_" /D UNDER_CE=$(CEVersion) /D _WIN32_WCE=$(CEVersion) /D "$(CePlatform)" /D "UNICODE" /D "_UNICODE" /D "_X86_" /D "x86" /D "_WIN32_WCE_CEPC" /D "_AFXDLL" /FR"X86Dbg/" /Fo"X86Dbg/" /Fd"X86Dbg/" /Gs8192 /GF /c /EHa

and the piece of code is this one:

      
TRY
	{
		int intArray[5] = { 16, 2, 77, 40, 12071 }; 
		int mtp;

		for(int i=-1;i<50;i++)
		{
			intArray[i]=i;
			mtp=intArray[i];
		}
		
	}
	CATCH( CException, e )
    {
		AfxMessageBox(_T("Problem here"));
	}
	END_CATCH

Open in new window

0
Comment
Question by:rileo8
  • 7
  • 5
14 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 36814913
Are you just adding the compoiler option manually? Try to set that is VS (from the docs):

------------------------------------>8-----------------------------------

To set this compiler option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.

Click the C/C++ folder.

Click the Code Generation property page.

Modify the Enable C++ Exceptions property.

------------------------------------>8-----------------------------------
0
 

Author Comment

by:rileo8
ID: 36814956
Hi,

i'm usinf EVC++ 4.0 so the only way to add it is by hand..

from the help:

 Project Options -> Type /EH in the text box, adding the desired exception-handling arguments.
0
 
LVL 86

Expert Comment

by:jkr
ID: 36815043
Hmm, could you give it a try to set that in the project options?
0
 

Author Comment

by:rileo8
ID: 36815118
I already set it, project oprions are:

/nologo /W3 /Zi /Od /I "..\jpeglib\\" /D "DEBUG" /D "_i386_" /D UNDER_CE=$(CEVersion) /D _WIN32_WCE=$(CEVersion) /D "$(CePlatform)" /D "UNICODE" /D "_UNICODE" /D "_X86_" /D "x86" /D "_WIN32_WCE_CEPC" /D "_AFXDLL" /FR"X86Dbg/" /Fo"X86Dbg/" /Fd"X86Dbg/" /Gs8192 /GF /c /EHa

so you can see /EHa at the end of the string

The problem is that wihout it it catch only c++ exception while with it it should catch also win32 exception....but it gives that error...
0
 
LVL 86

Expert Comment

by:jkr
ID: 36815235
Honestly, I wouldn't try to catch SEH exceptions with a C++ exception handler, these are simply two different things. Rather try to
LONG
WINAPI
MyExceptionHandler(LPEXCEPTION_POINTERS pe) {

    AfxMessageBox(_T("Problem here"));

    return EXCEPTION_EXECUTE_HANDLER;
}

//...

SetUnhandledExceptionFilter(MyExceptionHandler);

TRY
	{
		int intArray[5] = { 16, 2, 77, 40, 12071 }; 
		int mtp;

		for(int i=-1;i<50;i++)
		{
			intArray[i]=i;
			mtp=intArray[i];
		}
		
	}
	CATCH( CException, e )
    {
		AfxMessageBox(_T("Problem here"));
	}
	END_CATCH

Open in new window

0
 

Author Comment

by:rileo8
ID: 36815345
I did like this:


LONG WINAPI OurCrashHandler(EXCEPTION_POINTERS * /*ExceptionInfo*/)
{
    AfxMessageBox(_T("TAKEN"));

    return 0;
}

BOOL CDiagToolApp::InitInstance()
{

      SetUnhandledExceptionFilter(OurCrashHandler);

...

but it gives me compile error:

 error C2065: 'SetUnhandledExceptionFilter' : undeclared identifier
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 36815385
Ooops, sorry, my fault - "Windows CE: Unsupported.". But, since you are mainly after SEH exceptions, does the following work for you?
//...
        __try
	{
		int intArray[5] = { 16, 2, 77, 40, 12071 }; 
		int mtp;

		for(int i=-1;i<50;i++)
		{
			intArray[i]=i;
			mtp=intArray[i];
		}
		
	}
	__except(1)
        {
		AfxMessageBox(_T("Problem here"));
	}

Open in new window

0
 

Author Comment

by:rileo8
ID: 36815462
Now the code is like this:


      __try
    {
            regman->ReadString(_T("Language"));
      }
      __except(1)
    {
        AfxMessageBox(_T("Problem here"));
    }


and i don't have /EHa in the project settings

regman is a null pointer so rise an exception and it seems to work correctly.
0
 
LVL 86

Expert Comment

by:jkr
ID: 36815678
That's what is is supposed to do ;o)
0
 

Author Comment

by:rileo8
ID: 36818053
I've requested that this question be closed as follows:

Accepted answer: 0 points for rileo8's comment http:/Q_27361360.html#36815462

for the following reason:

Solved the issue
0
 
LVL 86

Expert Comment

by:jkr
ID: 36815988
Um, since your comment you suggested for closing this Q is basically what I wrote earlier - why are you not just closing this question?
0
 
LVL 86

Expert Comment

by:jkr
ID: 36818054
http://www.experts-exchange.com/Programming/Languages/CPP/Q_27361360.html?cid=1572#a36815385 already lines out what now should be the solution now, thus the objection.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now