C语言获取数组越界,除以零等异常
生活随笔
收集整理的這篇文章主要介紹了
C语言获取数组越界,除以零等异常
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#pragma once#include <windows.h>
#include <tchar.h>
#include <stdio.h>
//需求安裝windows sdk#define MAX_PATH 260#define STATUS_POSSIBLE_DEADLOCK ((unsigned long)0xC0000194L)
#define STATUS_MODULE_NOT_FOUND ((unsigned long)0xC06D007EL)
#define STATUS_PROCEDURE_NOT_FOUND ((unsigned long)0xC06D007FL)
#define STATUS_WIND32_EXCEPTION ((unsigned long)0x00003002L)typedef struct _EXCEPTION_INFO {unsigned long code;TCHAR info[MAX_PATH + 1];
} EXCEPTION_INFO, *P_EXCEPTION_INFO;unsigned long seh_filter(unsigned long code, PEXCEPTION_POINTERS pep) {static const EXCEPTION_INFO s_except_info[] = {{ EXCEPTION_ACCESS_VIOLATION, _T("Access violation") },{ EXCEPTION_ARRAY_BOUNDS_EXCEEDED, _T("Array bounds exceeded") },{ EXCEPTION_INT_OVERFLOW, _T("Integer overflow") },{ EXCEPTION_STACK_OVERFLOW, _T("Stack overflow") },{ STATUS_POSSIBLE_DEADLOCK, _T("Possible deadlokK") },{ EXCEPTION_INVALID_HANDLE, _T("An invalid handle was specified") },{ STATUS_MODULE_NOT_FOUND, _T("Module not found") },{ STATUS_PROCEDURE_NOT_FOUND, _T("Procedure not found") },{ STATUS_WIND32_EXCEPTION, _T("Wind32 exception") },{ ((unsigned long)0x00000000L), _T("Unkow Exceptions") }//...};unsigned int i;for (i = 0; s_except_info[i].code; i++){if (code == s_except_info[i].code){_tprintf_s(_T("Error Code: 0x%08X, Error Info: %s\n"), code, s_except_info[i].info);return EXCEPTION_EXECUTE_HANDLE;}}return EXCEPTION_CONTINUE_SEARCH;
}int example()
{int iRet = 0;__try {iRet /= 0;}__except (seh_filter(GetExceptionCode(), GetExceptionInformation())) {return GetLastError();}return iRet;
}
?
總結(jié)
以上是生活随笔為你收集整理的C语言获取数组越界,除以零等异常的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 异常和异常处理(windows平台)
- 下一篇: 发一个机器学习网站