C2712: Cannot use __try in functions that require object unwinding
Hello,
I am migrating a software writen with VC++ 6.0 to VS 2010/VC++2010. and I have a project which does not compile in Debug mode. I have:
Code:
LBSC_AppUserInfoList *
LBSC_Session::GetUsersInfo( const LBSC_Ticket *pTicket )
{
TSROut_GetUsersInfo sOut;
C_Buffer *pcbRet = NULL;
TSRIn_TicketPar InPar;
//...
ClntFree( (void *)sOut.szBuffer ); // dealoca o que veio do RPC
return( pList );
} // C2712 - Cannot use __try in functions that require object unwinding
and I haven´t any mention to __try
do you undestand?
Re: C2712: Cannot use __try in functions that require object unwinding
What is TSROut_GetUsersInfo ?
What is C_Buffer?
What is TSRIn_TicketPar ?
What is ClntFree?
What is hidden under //...?
What line of this code snippet produced the error"C2712 - Cannot use __try in functions that require object unwinding"?
Re: C2712: Cannot use __try in functions that require object unwinding
Quote:
Originally Posted by
michaelhsilva
return( pList );
Where did "pList" come from? It just pops up out of nowhere in your code.
The bottom line is that if you have a problem compiling code, it doesn't help if you're hiding code with comments or introduce variables and types no one knows what they are. It could be what's in those comments or maybe something is strange with the types you're using.
Code:
LBSC_AppUserInfoList *
LBSC_Session::GetUsersInfo( const LBSC_Ticket *pTicket )
{
return 0;
}
Still we don't know what LBSC_AppUserInfoList or what those types are, but if you took everything out of that function and just returned NULL, does the error go away? If it does go away, then it's all of those types we don't know about and/or the hidden code that is causing the problem.
Regards,
Paul McKenzie
Re: C2712: Cannot use __try in functions that require object unwinding
Also, have you look at Compiler Error C2712?
Re: C2712: Cannot use __try in functions that require object unwinding
I´ll put here the entire code. The line that pops the error up is the last '}'
Code:
LBSC_AppUserInfoList *
LBSC_Session::GetUsersInfo( const LBSC_Ticket *pTicket )
{
TSROut_GetUsersInfo sOut;
C_Buffer *pcbRet = NULL;
TSRIn_TicketPar InPar;
unsigned long ulExceptionCode = 0;
memset( (void*) &InPar, 0, sizeof(InPar));
if( !LBSC_ClntNet::GetRPCHandle( (char *)this->ServerAddr ) ){
return( NULL );
}
InPar.sTicket = BuildTickBuff(pTicket);
InPar.sCtrlInfo = ObtemControlInfo();
InPar.lSessionObj = this->obj;
boolean bNetError = TRUE;
boolean bRetry = FALSE;
do {
TSRIn_TicketPar DupInPar;
RpcTryExcept{
Duplicate( InPar, &DupInPar );
Criptografa( DupInPar );
sOut = RPC_Session_GetUsersInfo( DupInPar );
bNetError = FALSE;
bRetry = FALSE;
Free( DupInPar );
}
RpcExcept(1){
Free( DupInPar );
bRetry = LBSC_ClntNet::EnviaNovaRPC();
ulExceptionCode = RpcExceptionCode();
}
RpcEndExcept
} while( bRetry );
LBSC_ClntNet::FreeRPCHandle();
if( bNetError ) {
LBSC_ClntNet::TrataErroRPC( (char *)this->ServerAddr , ulExceptionCode);
return( NULL );
}
if ( !sOut.lTamBuff ) {
return ( NULL );
}
LBSC_AppUserInfoList *pList = NULL;
pcbRet = new C_Buffer( sOut.lTamBuff - sizeof(int) ); // pula o int do cbuffer; Vladimir Catao 29/01/96
if( !pcbRet ){ // sem memoria, considere um erro de rede; trate-o
return ( NULL );
}
pcbRet->PutData( (void*) (sOut.szBuffer + sizeof(int)), sOut.lTamBuff - sizeof(int)); // pula o int do cbuffer; Vladimir Catao 29/01/96
pcbRet->Rewind();
pList = MakeAppUserInfoList( *pcbRet );
delete pcbRet;
ClntFree( (void *)sOut.szBuffer ); // dealoca o que veio do RPC
return( pList );
}
Re: C2712: Cannot use __try in functions that require object unwinding
Quote:
Originally Posted by
Ejaz
I´ve seen, but does not help the code doesn´t mention __try...
Re: C2712: Cannot use __try in functions that require object unwinding
Quote:
Originally Posted by
michaelhsilva
I´ll put here the entire code. The line that pops the error up is the last '}'
What is this?
Also, did you do as I stated? Take all of that code out and just return NULL. Does the error go away? If it does, then reintroduce the code one segment at a time until the error shows up again. Then you know what causes the error and you can then further investigate.
Regards,
Paul McKenzie
Re: C2712: Cannot use __try in functions that require object unwinding
I´ve commented the body of the function and put return 0, but the error run to another line a ´}´ too...
Re: C2712: Cannot use __try in functions that require object unwinding
Quote:
Originally Posted by
michaelhsilva
I´ve commented the body of the function and put return 0, but the error run to another line a ´}´ too...
I don't understand. Does the error for that function in question go away? It isn't important if another function has an error, does the function you commented the code out of have an error now?
You also didn't answer what that "RpcTryExcept" is or what it does.
Regards,
Paul McKenzie
Re: C2712: Cannot use __try in functions that require object unwinding
A ha!!!
i found
Code:
#define RpcTryExcept \
__try \
{
// trystmts
#define RpcExcept(expr) \
} \
__except (expr) \
{
// exceptstmts
Re: C2712: Cannot use __try in functions that require object unwinding
A ha!!!
i found
Code:
#define RpcTryExcept \
__try \
{
// trystmts
#define RpcExcept(expr) \
} \
__except (expr) \
{
// exceptstmts
Regards,
Michael
Re: C2712: Cannot use __try in functions that require object unwinding
I´ll do like you posted Paul.
Regards,
Michael
Re: C2712: Cannot use __try in functions that require object unwinding
I need Help!
http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx says that: C2712 can occur if you compile with /clr:pure and declare a static array of pointers-to-functions in a __try block.
I am not compiling with /clr:pure...
Paul, I did not tested line by line yet but making a test project with the code
Code:
RpcTryExcept{
}
RpcExcept(1){
}
RpcEndExcept
it compiles well but in the project of VC++ 6.0, that I am migrating to VS 2010, does not compile, in other words the __try block without code inside.
could you help me?
Re: C2712: Cannot use __try in functions that require object unwinding
Quote:
Originally Posted by
michaelhsilva
Did you read the beginning of that page?
Quote:
With /EHsc, a function with structured exception handling cannot have objects that require unwinding (destruction).
Possible solutions:
Move code that requires SEH to another function.
Rewrite functions that use SEH to avoid the use of local variables and parameters that have destructors. Do not use SEH in constructors or destructors.
Compile without /EHsc.
The reason and possible solutions are in the quote above. What you mentioned is just one possible reason, not the only reason for the issue.
Why not do something I've mentioned three times now? Remove code from the __try/__except until you get a good compile. When you do get a good compile, you know exactly which functions need to be moved, changed, whatever, to get all of your code to compile.
Regards,
Paul McKenzie
Re: C2712: Cannot use __try in functions that require object unwinding
Quote:
Originally Posted by
Paul McKenzie
Did you read the beginning of that page?
The reason and possible solutions are in the quote above. What you mentioned is just one possible reason, not the only reason for the issue.
Why not do something I've mentioned three times now? Remove code from the __try/__except until you get a good compile. When you do get a good compile, you know exactly which functions need to be moved, changed, whatever, to get all of your code to compile.
Regards,
Paul McKenzie
I understand now that it´s not the code inside __try / __except because only __try /] __except itself make the error appear without code inside. I´ve moved the __try / __except block to another function passing the right parameters and it compiles.
Thank you very much.
Regards,
Michael