source: trunk/src/win32_exception.cpp @ 564

Revision 564, 1.2 KB checked in by Eoin, 11 years ago (diff)

Added win32_exception class.

Line 
1
2
3#include "stdAfx.hpp"
4
5#include "win32_exception.hpp"
6#include "eh.h"
7
8void win32_exception::install_handler()
9{
10    _set_se_translator(win32_exception::translate);
11}
12
13void win32_exception::translate(unsigned code, EXCEPTION_POINTERS* info)
14{
15    // Windows guarantees that *(info->ExceptionRecord) is valid
16    switch (code) {
17    case EXCEPTION_ACCESS_VIOLATION:
18        throw access_violation(*(info->ExceptionRecord));
19        break;
20    default:
21        throw win32_exception(*(info->ExceptionRecord));
22    }
23}
24
25win32_exception::win32_exception(const EXCEPTION_RECORD& info)
26: mWhat("Win32 exception"), mWhere(info.ExceptionAddress), mCode(info.ExceptionCode)
27{
28    switch (info.ExceptionCode) {
29    case EXCEPTION_ACCESS_VIOLATION:
30        mWhat = "Access violation";
31        break;
32    case EXCEPTION_FLT_DIVIDE_BY_ZERO:
33    case EXCEPTION_INT_DIVIDE_BY_ZERO:
34        mWhat = "Division by zero";
35        break;
36    }
37}
38
39access_violation::access_violation(const EXCEPTION_RECORD& info)
40: win32_exception(info), mIsWrite(false), mBadAddress(0)
41{
42    mIsWrite = info.ExceptionInformation[0] == 1;
43    mBadAddress = reinterpret_cast<win32_exception::Address>(info.ExceptionInformation[1]);
44}
Note: See TracBrowser for help on using the repository browser.