Skip to content

Commit

Permalink
Первый коммит
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnaider Pavel committed Jul 11, 2017
0 parents commit 9e708ac
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.7)
project(Skilled_Venus)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(Skilled_Venus ${SOURCE_FILES})
46 changes: 46 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <setjmp.h>
#include <signal.h>
#include <iostream>

jmp_buf here;

struct TestRAII {
TestRAII(int name): name(name) {
std::cout << __PRETTY_FUNCTION__ << " " << name << std::endl;
}

virtual ~TestRAII() {
std::cout << __PRETTY_FUNCTION__ << " " << name << std::endl;
}

int name;
};

void hardFail() {
TestRAII testRAII(2);
*(static_cast<int*>(0)) = 0;
}

void sighandler(int signal) {
longjmp(here, signal);
}

int main() {
try {
TestRAII testRAII(1);

signal(SIGSEGV, sighandler);
if (int err = setjmp(here)) {
char buffer[64];
snprintf(buffer, sizeof(buffer), "signal handler %d", err);
throw std::runtime_error(buffer);
}

std::cout << "Hello, World!" << std::endl;

hardFail();
} catch (std::exception const& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}

0 comments on commit 9e708ac

Please sign in to comment.