Solved

evc++ /EHa option cause error LNK2019

Posted on 2011-09-29
14
610 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

856 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