Solved

evc++ /EHa option cause error LNK2019

Posted on 2011-09-29
14
609 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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
 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

778 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