The code is copied from Microsoft MSDN. However, I can not why
" *p = 12; " will cause an access violation exception. Any suggestion?
#include <stdio.h>
#include <windows.h> // for EXCEPTION_ACCESS_VIOLATION
#include <excpt.h>
int filter(unsigned int code, struct _EXCEPTION_POINTERS ep) {
puts(“in filter.”);
if (code == EXCEPTION_ACCESS_VIOLATION) {
puts(“caught AV as expected.”);
return EXCEPTION_EXECUTE_HANDLER;
}
else {
puts(“didn’t catch AV, unexpected.”);
return EXCEPTION_CONTINUE_SEARCH;
};
}
int main()
{
//int p = 0x00000000; // pointer to NULL
int* p = NULL; // pointer to NULL
puts(“hello”);
__try{
puts(“in try”);
__try{
puts(“in try”);
*p = 12; // causes an access violation exception;
// put(&p);
}__finally{
puts("in finally. termination: ");
puts(AbnormalTermination() ? “\tabnormal” : “\tnormal”);
}
}__except(filter(GetExceptionCode(), GetExceptionInformation())){
puts(“in except”);
}
puts(“world”);
}</excpt.h></windows.h></stdio.h>
At 09:20 AM 3/5/2004, Zhihua LI wrote:
The code is copied from Microsoft MSDN. However, I can not why
" *p = 12; " will cause an access violation exception. Any suggestion?
Coz p == NULL, so the code is trying to write the value 12 to address
0x00000000 … definitely an access violation.
hi
I see… Thanks
sometime I make this type error. But compiler can not capture it.
Best Regards
zhihua
“Mark S. Edwards”
To: “Windows System Software Devs Interest List”
Sent by: cc:
bounce-169206-14464@li Subject: Re: [ntdev] about __Try,
sts.osr.com
03/05/2004 05:34 PM
Please respond to
“Windows System
Software Devs Interest
List”
At 09:20 AM 3/5/2004, Zhihua LI wrote:
>The code is copied from Microsoft MSDN. However, I can not why
>
>" *p = 12; " will cause an access violation exception. Any suggestion?
>
Coz p == NULL, so the code is trying to write the value 12 to address
0x00000000 … definitely an access violation.
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@ctl.creative.com
To unsubscribe send a blank email to xxxxx@lists.osr.com