2424
2525using namespace xtd ;
2626using namespace xtd ::diagnostics;
27+ using namespace xtd ::helpers;
2728using namespace xtd ::threading;
2829
2930struct thread ::data {
@@ -107,7 +108,7 @@ bool thread::auto_join() const noexcept {
107108}
108109
109110thread& thread::auto_join (bool value) {
110- if (is_aborted () || is_stopped ()) throw thread_state_exception {} ;
111+ if (is_aborted () || is_stopped ()) throw_helper::throws (exception_case::thread_state) ;
111112 data_->auto_join = value;
112113 return *this ;
113114}
@@ -178,7 +179,7 @@ xtd::threading::thread_priority thread::priority() const noexcept {
178179
179180thread& thread::priority (xtd::threading::thread_priority value) {
180181 if (!enum_object<>::is_defined (value)) xtd::helpers::throw_helper::throws (xtd::helpers::exception_case::argument);
181- if (is_aborted () || is_stopped ()) throw thread_state_exception {} ;
182+ if (is_aborted () || is_stopped ()) throw_helper::throws (exception_case::thread_state) ;
182183
183184 if (data_->priority == value) return *this ;
184185 data_->priority = value;
@@ -195,7 +196,7 @@ xtd::threading::thread_state thread::thread_state() const noexcept {
195196}
196197
197198void thread::abort () {
198- if (is_unstarted () || is_suspended ()) throw thread_state_exception {} ;
199+ if (is_unstarted () || is_suspended ()) throw_helper::throws (exception_case::thread_state) ;
199200
200201 data_->state |= xtd::threading::thread_state::abort_requested;
201202
@@ -230,7 +231,7 @@ void thread::join() {
230231}
231232
232233bool thread::join (int32 milliseconds_timeout) {
233- if (is_unstarted ()) throw thread_state_exception {} ;
234+ if (is_unstarted ()) throw_helper::throws (exception_case::thread_state) ;
234235 if (milliseconds_timeout < timeout::infinite) xtd::helpers::throw_helper::throws (xtd::helpers::exception_case::argument);
235236
236237 if (data_->interrupted == true ) interrupt_internal ();
@@ -282,7 +283,7 @@ bool thread::join_all(const time_span& timeout) {
282283}
283284
284285void thread::resume () {
285- if (is_unstarted () || !is_suspended ()) throw thread_state_exception {} ;
286+ if (is_unstarted () || !is_suspended ()) throw_helper::throws (exception_case::thread_state) ;
286287
287288 native::thread::resume (data_->handle );
288289 data_->state &= ~xtd::threading::thread_state::suspended;
@@ -312,27 +313,27 @@ void thread::spin_wait(int32 iterations) {
312313}
313314
314315void thread::start () {
315- if (!is_unstarted ()) throw thread_state_exception {} ;
316+ if (!is_unstarted ()) throw_helper::throws (exception_case::thread_state) ;
316317 if (data_->thread_start .is_empty () && data_->parameterized_thread_start .is_empty ()) xtd::helpers::throw_helper::throws (xtd::helpers::exception_case::invalid_operation);
317318 data_->state &= ~xtd::threading::thread_state::unstarted;
318319 data_->joinable = true ;
319320 data_->parameter = nullptr ;
320321 data_->handle = native::thread::create ([&](intptr arg) {
321322 reinterpret_cast <threading::thread*>(arg)->thread_proc ();
322323 }, reinterpret_cast <intptr>(data_->safe_thread ), data_->max_stack_size , is_suspended (), data_->thread_id );
323- if (data_->handle == invalid_handle) throw io::io_exception {} ;
324+ if (data_->handle == invalid_handle) throw_helper::throws (exception_case::io) ;
324325}
325326
326327void thread::start (std::any param) {
327- if (!is_unstarted ()) throw thread_state_exception {} ;
328+ if (!is_unstarted ()) throw_helper::throws (exception_case::thread_state) ;
328329 if (data_->parameterized_thread_start .is_empty ()) xtd::helpers::throw_helper::throws (xtd::helpers::exception_case::invalid_operation);
329330 data_->state &= ~xtd::threading::thread_state::unstarted;
330331 data_->joinable = true ;
331332 data_->parameter = param;
332333 data_->handle = native::thread::create ([](intptr arg) {
333334 reinterpret_cast <thread*>(arg)->thread_proc ();
334335 }, reinterpret_cast <intptr>(data_->safe_thread ), data_->max_stack_size , is_suspended (), data_->thread_id );
335- if (data_->handle == invalid_handle) throw io::io_exception {} ;
336+ if (data_->handle == invalid_handle) throw_helper::throws (exception_case::io) ;
336337}
337338
338339thread thread::start_new (const xtd::threading::thread_start& start) {
@@ -348,7 +349,7 @@ thread thread::start_new(const xtd::threading::parameterized_thread_start& start
348349}
349350
350351void thread::suspend () {
351- if (!is_alive ()) throw thread_state_exception {} ;
352+ if (!is_alive ()) throw_helper::throws (exception_case::thread_state) ;
352353
353354 data_->state |= xtd::threading::thread_state::suspend_requested;
354355 native::thread::suspend (data_->handle );
@@ -485,7 +486,7 @@ void thread::interrupt_internal() {
485486 data_->interrupted = false ;
486487 data_->state &= ~xtd::threading::thread_state::wait_sleep_join;
487488 if (data_->managed_thread_id == 1 ) environment::raise (signal::interrupt);
488- else throw thread_interrupted_exception {} ;
489+ else throw_helper::throws (exception_case::thread_interrupted) ;
489490}
490491
491492bool thread::is_aborted () const noexcept {
@@ -546,8 +547,8 @@ void thread::thread_proc() {
546547 else if (!data_->parameterized_thread_start .is_empty ()) data_->parameterized_thread_start (data_->parameter );
547548 else xtd::helpers::throw_helper::throws (xtd::helpers::exception_case::invalid_operation);
548549
549- if (is_aborted ()) throw thread_abort_exception {} ;
550- if (is_aborted ()) throw thread_interrupted_exception {} ;
550+ if (is_aborted ()) throw_helper::throws (exception_case::thread_abort) ;
551+ if (is_aborted ()) throw_helper::throws (exception_case::thread_interrupted) ;
551552
552553 data_->state |= xtd::threading::thread_state::stopped;
553554 data_->end_thread_event .set ();
0 commit comments