What does __try do?

What does __try do?

Post by » Sun, 12 Feb 2006 06:06:28


Hello, I have some code which I need to examine, can someone explain
to me what does __try do in the following snippet:
(p.s. this is kernel mode)

__try {
if( s1 ) {
ansiS.Buffer = NULL;
if( NT_SUCCESS( RtlUnicodeStringToAnsiString( &ansiS, s1,
TRUE ))) {
if( ansiS.Buffer[0] )
strccpy( globalS, ansiS.Buffer);
}
RtlFreeAnsiString( &ansiS );
}
}
__except( EXCEPTION_EXECUTE_HANDLER ) {
if( ansiS.Buffer ) RtlFreeAnsiString( &ansiS );
strcpy( globalS, "error" );
}
 
 
 

What does __try do?

Post by Don Bur » Sun, 12 Feb 2006 06:59:58

Nothing useful. It appears the author of this code was hoping that they
could catch page faults that can occur in RtlUnicodeStringToAnsiString and
will crash the system if running at DISPATCH_LEVEL, but page faults are not
caught by try execept blocks.

--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

 
 
 

What does __try do?

Post by » Sun, 12 Feb 2006 08:12:50

Would it make any difference if what was actually used was
try/except and NOT __try/__except?



not
 
 
 

What does __try do?

Post by Don Bur » Sun, 12 Feb 2006 08:35:43

No __try __except are the Structured Exception Handling the kernel uses,
using try except is a bad idea in the kernel.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply
 
 
 

What does __try do?

Post by Kim Grma » Sun, 12 Feb 2006 23:52:52

Hi try,


Also, there is no try/except -- there is try/catch but that's a C++ concept
(language level), and shouldn't generally be used to catch structured exceptions
(OS level)

Best Regards,
Kim Grman