-
May 16th, 2012, 12:43 PM
#1
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?
-
May 16th, 2012, 02:06 PM
#2
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"?
Victor Nijegorodov
-
May 16th, 2012, 04:50 PM
#3
Re: C2712: Cannot use __try in functions that require object unwinding
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
-
May 17th, 2012, 06:34 AM
#4
Re: C2712: Cannot use __try in functions that require object unwinding
Also, have you look at Compiler Error C2712?
-
May 17th, 2012, 01:22 PM
#5
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 );
}
-
May 17th, 2012, 01:24 PM
#6
Re: C2712: Cannot use __try in functions that require object unwinding
Originally Posted by Ejaz
I´ve seen, but does not help the code doesn´t mention __try...
-
May 17th, 2012, 01:29 PM
#7
Re: C2712: Cannot use __try in functions that require object unwinding
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
-
May 17th, 2012, 01:33 PM
#8
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...
-
May 17th, 2012, 01:41 PM
#9
Re: C2712: Cannot use __try in functions that require object unwinding
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
-
May 17th, 2012, 02:06 PM
#10
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
-
May 17th, 2012, 02:12 PM
#11
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
-
May 17th, 2012, 02:13 PM
#12
Re: C2712: Cannot use __try in functions that require object unwinding
I´ll do like you posted Paul.
Regards,
Michael
-
May 18th, 2012, 12:24 PM
#13
-
May 18th, 2012, 01:13 PM
#14
Re: C2712: Cannot use __try in functions that require object unwinding
Originally Posted by michaelhsilva
Did you read the beginning of that page?
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
Last edited by Paul McKenzie; May 18th, 2012 at 01:16 PM.
-
May 18th, 2012, 02:08 PM
#15
Re: C2712: Cannot use __try in functions that require object unwinding
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|