2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
21 #include "..\stdafx.h"
\r
22 #include "win32exception.h"
\r
24 void Win32Exception::InstallHandler() {
\r
25 _set_se_translator(Win32Exception::Handler);
\r
28 void Win32Exception::Handler(unsigned int errorCode, EXCEPTION_POINTERS* pInfo) {
\r
31 case EXCEPTION_ACCESS_VIOLATION:
\r
32 throw Win32AccessViolationException(*(pInfo->ExceptionRecord));
\r
36 throw Win32Exception(*(pInfo->ExceptionRecord));
\r
40 Win32Exception::Win32Exception(const EXCEPTION_RECORD& info) : message_("Win32 exception"), location_(info.ExceptionAddress), errorCode_(info.ExceptionCode)
\r
42 switch(info.ExceptionCode)
\r
44 case EXCEPTION_ACCESS_VIOLATION:
\r
45 message_ = "Access violation";
\r
47 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
\r
48 case EXCEPTION_INT_DIVIDE_BY_ZERO:
\r
49 message_ = "Divide by zero";
\r
54 Win32AccessViolationException::Win32AccessViolationException(const EXCEPTION_RECORD& info) : Win32Exception(info), isWrite_(false), badAddress_(0)
\r
56 isWrite_ = info.ExceptionInformation[0] == 1;
\r
57 badAddress_ = reinterpret_cast<Win32Exception::Address>(info.ExceptionInformation[1]);
\r
60 const char* Win32AccessViolationException::what() const {
\r
61 sprintf_s<>(messageBuffer_, "Access violation at %p, trying to %s %p", Location(), isWrite_?"write":"read", badAddress_);
\r
63 return messageBuffer_;
\r