#include <stdio.h> int main() { char szBuff[1]; for(char *pBuff = szBuff;;pBuff++) *pBuff = '$'; printf("I'll never reach Here !!\n"); return 0; }when run in a debugger gives the following error: Unhandled exception in test1.exe: 0xC0000005: Access Violation But does not display any sort of exception when run outside a debugger and crash directly.The system depends on information saved on the stack to unwind exceptions; as the whole stack is trashed in this case, attempting to call the default handler (which would display the error message box, and optionally attach a debugger) will only result in a new exception, upon which the program will be terminated immediately.Under a debugger however, the system will suspend the program and notify the debugger, giving it a chance to deal with the problem first. #include <stdio.h> int main() { char szBuff[1]; for(char *pBuff = szBuff+1024;;pBuff++) // added the +1024 *pBuff = '$'; printf("I'll never reach Here !!\n"); return 0; }and I got these 2 errors... The instruction at "0x0040b4cf" referenced memory at "0x00133000". The memory could not be written && The instruction at "0x77f84abe" referenced memory at "0x24242430". The memory could not be read That little jump ahead saved part of the stack !
to masterz(): 你给出的第一个例子确实捕获不到,非常感谢! 可是我如何在茫茫的代码中找到那条出错的语句。 有什么快捷的调试方法?望赐教。
怎样捕获#include <stdio.h> int main() { char szBuff[1]; for(char *pBuff = szBuff;;pBuff++) *pBuff = '$'; printf("I'll never reach Here !!\n"); return 0; }的异常?0xC0000005无法捕获吗?
另外那台机器是2cpu的有没有关系?我想知道有什么是__try捕获不到的?
_try{
}
_except(...){
}
都可以截获,不能截获的是
1,其他线程的错误,比如CSocket会创建新的线程,捕获不到。
2,MFC的某些抛出的异常捕获不到。
3,COM的异常通常不能通过该方式捕获
4,new 的内存使用超界,delete导致的异常。
1:我的程序没有使用CSocket,用的是api函数
2:lhj:能否举个mfc抛出的__try __except捕获不到的异常的例子,我想做个实验以验证。
3:我没有用到COM
4: 给个例子好吗,我非常需要。
谢谢!
new的分配是在应用程序堆上分配的.你即是网络游戏,那么字符串可以放在字符缓冲池中. (见数据结构).而其他的固定大小的数据.比方可能要用到500个用户的数据.则可以在程序启动时分配一个1000 个单元的数组,建立空闲单元的索引, 每次从中 取一个存放.不要 想到什么时候要内存了就用NEW去分配.而且你最好不要用NEW.用HeapAlloc或者GlobalAlloc分配可移动内存.这些内存是系统可移动的,从 而避免碎片出现.只是使用时比较麻烦,要先锁定. 可以看< WINDOWS核心编程>
int main()
{
char szBuff[1];
for(char *pBuff = szBuff;;pBuff++)
*pBuff = '$';
printf("I'll never reach Here !!\n");
return 0;
}when run in a debugger gives the following error:
Unhandled exception in test1.exe: 0xC0000005: Access Violation
But does not display any sort of exception when run
outside a debugger and crash directly.The system depends on information saved on the stack to unwind exceptions;
as the whole stack is trashed in this case, attempting to call the default
handler (which would display the error message box, and optionally attach a
debugger) will only result in a new exception, upon which the program will
be terminated immediately.Under a debugger however, the system will suspend the program and notify the
debugger, giving it a chance to deal with the problem first.
#include <stdio.h>
int main()
{
char szBuff[1];
for(char *pBuff = szBuff+1024;;pBuff++) // added the +1024
*pBuff = '$';
printf("I'll never reach Here !!\n");
return 0;
}and I got these 2 errors...
The instruction at "0x0040b4cf" referenced memory at "0x00133000". The
memory could not be written
&&
The instruction at "0x77f84abe" referenced memory at "0x24242430". The
memory could not be read
That little jump ahead saved part of the stack !
你给出的第一个例子确实捕获不到,非常感谢!
可是我如何在茫茫的代码中找到那条出错的语句。
有什么快捷的调试方法?望赐教。
int main()
{
char szBuff[1];
for(char *pBuff = szBuff;;pBuff++)
*pBuff = '$';
printf("I'll never reach Here !!\n");
return 0;
}的异常?0xC0000005无法捕获吗?