Skip to content

Commit

Permalink
throw only in main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Aug 10, 2023
1 parent 90a2717 commit 26373eb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/xtd.core/src/xtd/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "../../include/xtd/unused.h"
#include "../../include/xtd/io/directory.h"
#include "../../include/xtd/io/path.h"
#include "../../include/xtd/threading/thread.h"
#define __XTD_CORE_NATIVE_LIBRARY__
#include <xtd/native/environment.h>
#undef __XTD_CORE_NATIVE_LIBRARY__
Expand Down Expand Up @@ -68,21 +69,21 @@ class environment::signal_catcher {
std::signal(signal, signal_catcher::on_abnormal_termination_occured);
signal_cancel_event_args e {xtd::signal::abnormal_termination};
environment::on_cancel_signal(e);
if (!e.cancel()) throw xtd::threading::thread_abort_exception(csf_);
if (xtd::threading::thread::current_thread().is_main_thread() && !e.cancel()) throw xtd::threading::thread_abort_exception(csf_);
}

static void on_floating_point_exception_occured(int32 signal) {
std::signal(signal, signal_catcher::on_floating_point_exception_occured);
signal_cancel_event_args e {xtd::signal::floating_point_exception};
environment::on_cancel_signal(e);
if (!e.cancel()) throw xtd::arithmetic_exception(csf_);
if (xtd::threading::thread::current_thread().is_main_thread() && !e.cancel()) throw xtd::arithmetic_exception(csf_);
}

static void on_illegal_instruction_occured(int32 signal) {
std::signal(signal, signal_catcher::on_illegal_instruction_occured);
signal_cancel_event_args e {xtd::signal::illegal_instruction};
environment::on_cancel_signal(e);
if (!e.cancel()) throw xtd::invalid_operation_exception(csf_);
if (xtd::threading::thread::current_thread().is_main_thread() && !e.cancel()) throw xtd::invalid_operation_exception(csf_);
}

static void on_interrupt_occured(int32 signal) {
Expand All @@ -91,7 +92,7 @@ class environment::signal_catcher {
environment::on_cancel_signal(se);
console_cancel_event_args ce {console_special_key::control_c};
ce.cancel(console::on_cancel_key_press(static_cast<int32>(console_special_key::control_c)));
if (!se.cancel() && !ce.cancel()) throw xtd::interrupt_exception(csf_);
if (xtd::threading::thread::current_thread().is_main_thread() && !se.cancel() && !ce.cancel()) throw xtd::interrupt_exception(csf_);
}

static void on_program_exit() {
Expand Down

0 comments on commit 26373eb

Please sign in to comment.