Skip to content

Commit 3bfde4b

Browse files
committed
replace __external_exceptions by xtd::helpers::throw_helper
1 parent bd36e32 commit 3bfde4b

File tree

8 files changed

+28
-165
lines changed

8 files changed

+28
-165
lines changed

src/xtd.core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,6 @@ add_sources(
797797
include/xtd/internal/__enum_definition_to_enum_collection.hpp
798798
include/xtd/internal/__enum_introspection.hpp
799799
include/xtd/internal/__enumerable_collection.hpp
800-
include/xtd/internal/__external_exceptions.hpp
801800
include/xtd/internal/__floating_point_formatter.hpp
802801
include/xtd/internal/__format_exception.hpp
803802
include/xtd/internal/__format_information.hpp
@@ -1218,7 +1217,6 @@ add_sources(
12181217
src/xtd/diagnostics/trace_source.cpp
12191218
src/xtd/diagnostics/trace_switch.cpp
12201219
src/xtd/helpers/throw_helper.cpp
1221-
src/xtd/internal/__external_exceptions.cpp
12221220
src/xtd/internal/__format_exception.cpp
12231221
src/xtd/internal/__format_stringer.cpp
12241222
src/xtd/internal/__iformatable_formatter.cpp

src/xtd.core/include/xtd/array.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#pragma once
55
#define __XTD_CORE_INTERNAL__
66
#include "internal/__array_definition.hpp"
7-
#include "internal/__external_exceptions.hpp"
7+
#include "helpers/throw_helper.hpp"
88
#undef __XTD_CORE_INTERNAL__
99
#include "collections/generic/helpers/equator.hpp"
1010
#include "collections/generic/enumerator.hpp"
@@ -109,13 +109,13 @@ namespace xtd {
109109
#include "array_.hpp"
110110
#undef __XTD_ARRAY_INTERNAL__
111111
#define __XTD_CORE_INTERNAL__
112-
#include "internal/__external_exceptions.hpp"
112+
#include "helpers/throw_helper.hpp"
113113
#undef __XTD_CORE_INTERNAL__
114114

115115
/// @cond
116116
template<class source_t>
117117
const xtd::linq::enumerable::ienumerable<xtd::array<source_t>>& xtd::linq::enumerable::chunk(const ienumerable<source_t>& source, size_t size) {
118-
if (size == 0) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
118+
if (size == 0) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);
119119
static thread_local auto chunks = __opaque_xtd_linq_enumerable_collection__<xtd::array<source_t>> {};
120120
chunks = __opaque_xtd_linq_enumerable_collection__<xtd::array<source_t>> {};
121121
auto chunk = std::vector<source_t> {};

src/xtd.core/include/xtd/array_.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,27 @@ template<class type_t, class allocator_t>
5858
inline type_t& xtd::basic_array<type_t, allocator_t>::operator()(const xtd::array<xtd::size>& indexes) {
5959
auto position = xtd::size {0};
6060
for (auto index1 = xtd::size {0}; index1 < indexes.size(); ++index1) {
61-
if (indexes[index1] >= get_length(index1)) __throw_index_out_of_range_exception(__FILE__, __LINE__, __func__);
61+
if (indexes[index1] >= get_length(index1)) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::index_out_of_range);
6262
auto multiplicand = xtd::size {1};
6363
for (auto index2 = index1 + 1; index2 < indexes.size(); ++index2)
6464
multiplicand *= get_length(index2);
6565
position += indexes[index1] * multiplicand;
6666
}
67-
if (position >= size()) __throw_index_out_of_range_exception(__FILE__, __LINE__, __func__);
67+
if (position >= size()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::index_out_of_range);
6868
return data_->items[position];
6969
}
7070

7171
template<class type_t, class allocator_t>
7272
inline const type_t& xtd::basic_array<type_t, allocator_t>::operator()(const xtd::array<xtd::size>& indexes) const {
7373
auto position = xtd::size {0};
7474
for (auto index1 = xtd::size {0}; index1 < indexes.size(); ++index1) {
75-
if (indexes[index1] >= get_length(index1)) __throw_index_out_of_range_exception(__FILE__, __LINE__, __func__);
75+
if (indexes[index1] >= get_length(index1)) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::index_out_of_range);
7676
auto multiplicand = xtd::size {1};
7777
for (auto index2 = index1 + 1; index2 < indexes.size(); ++index2)
7878
multiplicand *= get_length(index2);
7979
position += indexes[index1] * multiplicand;
8080
}
81-
if (position >= size()) __throw_index_out_of_range_exception(__FILE__, __LINE__, __func__);
81+
if (position >= size()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::index_out_of_range);
8282
return data_->items[position];
8383
}
8484

src/xtd.core/include/xtd/basic_array.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ namespace xtd {
239239
/// @return Reference to the requested element.
240240
/// @exception xtd::index_out_of_range_exception If `index` is not within the range of the container.
241241
virtual reference at(size_type index) {
242-
if (index >= count()) __throw_index_out_of_range_exception(__FILE__, __LINE__, __func__);
242+
if (index >= count()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::index_out_of_range);
243243
return (reference)data_->items.at(index);
244244
}
245245
/// @brief Returns a reference to the element at specified location pos, with bounds checking.
246246
/// @param index The position of the element to return.
247247
/// @return Reference to the requested element.
248248
/// @exception xtd::index_out_of_range_exception If `index` is not within the range of the container.
249249
virtual const_reference at(size_type index) const {
250-
if (index >= count()) __throw_index_out_of_range_exception(__FILE__, __LINE__, __func__);
250+
if (index >= count()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::index_out_of_range);
251251
return (reference)data_->items.at(index);
252252
}
253253

@@ -261,9 +261,9 @@ namespace xtd {
261261

262262
void copy_to(xtd::array<type_t>& array, size_type index) const override {
263263
/// @todo uncomment want array remamed into array.
264-
//if (array.rank() != 1) __throw_argument_exception(__FILE__, __LINE__, __func__);
265-
if (rank() != 1) __throw_rank_exception(__FILE__, __LINE__, __func__);
266-
if (index + length() > array.size()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
264+
//if (array.rank() != 1) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument);
265+
if (rank() != 1) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::rank);
266+
if (index + length() > array.size()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);
267267
for (auto increment = size_type {0}; increment < length(); ++increment)
268268
array[index + increment] = at(increment);
269269
}
@@ -293,14 +293,14 @@ namespace xtd {
293293
explicit basic_array_enumerator(const basic_array& items, size_type version) : items_(items), version_(version) {}
294294

295295
const value_type& current() const override {
296-
if (version_ != items_.data_->version) __throw_invalid_operation_exception("Collection was modified; enumeration operation may not execute.", __FILE__, __LINE__, __func__);
296+
if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
297297
if (index_ < items_.count()) return items_[index_];
298298
static thread_local auto default_value = value_type {};
299299
return default_value;
300300
}
301301

302302
bool move_next() override {
303-
if (version_ != items_.data_->version) __throw_invalid_operation_exception("Collection was modified; enumeration operation may not execute.", __FILE__, __LINE__, __func__);
303+
if (version_ != items_.data_->version) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
304304
return ++index_ < items_.count();
305305
}
306306

@@ -343,7 +343,7 @@ namespace xtd {
343343
/// The following code example uses xtd::array::get_lower_bound and xtd::array::get_upper_bound to initialize a one-dimensional array and a multidimensional array.
344344
/// @include array_get_lower_bound.cpp
345345
constexpr size_type get_lower_bound(size_type dimension) const {
346-
if (dimension >= rank()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
346+
if (dimension >= rank()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);
347347
return data_->lower_bound[dimension];
348348
}
349349

@@ -355,7 +355,7 @@ namespace xtd {
355355
/// The following code example uses xtd::array::get_lower_bound and xtd::array::get_upper_bound to initialize a one-dimensional array and a multidimensional array.
356356
/// @include array_get_lower_bound.cpp
357357
constexpr size_type get_upper_bound(size_type dimension) const {
358-
if (dimension >= rank()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
358+
if (dimension >= rank()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);
359359
return data_->upper_bound[dimension];
360360
}
361361

@@ -385,7 +385,7 @@ namespace xtd {
385385
/// @remarks If the current size is less than `count`, additional default-inserted elements are appended.
386386
void resize(size_type new_size, value_type value) {
387387
if (new_size == length()) return;
388-
if (new_size > max_size()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
388+
if (new_size > max_size()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);
389389
++data_->version;
390390
data_->items.resize(new_size, value);
391391
data_->upper_bound[0] = new_size - 1;
@@ -441,7 +441,7 @@ namespace xtd {
441441
/// The following code example shows how to determine the index of the first occurrence of a specified element.
442442
/// @include array_index_of.cpp
443443
static size_type index_of(const basic_array& array, const value_type& value, size_type index, size_type count) {
444-
if (index > array.length() || index + count > array.length()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
444+
if (index > array.length() || index + count > array.length()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);
445445

446446
if (array.size() == 0) return npos;
447447
for (auto increment = size_type {0}; increment < count; ++increment) {
@@ -462,7 +462,7 @@ namespace xtd {
462462
/// @remarks This method uses std::reverse to reverse the order of the elements, such that the element at xtd::basic_array <type_t>[i], where `i` is any index within the range, moves to xtd::basic_array <type_t>[j], where `j` equals index plus index plus count minus `i` minus 1.
463463
/// @remarks This method is an O(n) operation, where n is `count`.
464464
static void reverse(basic_array& array, size_type index, size_type count) {
465-
if (index > array.size() || index + count > array.size()) __throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);
465+
if (index > array.size() || index + count > array.size()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);
466466
if (count == 0) return;
467467
++array.data_->version;
468468
std::reverse(array.data_->items.begin() + index, array.data_->items.begin() + index + count);
@@ -538,7 +538,7 @@ namespace xtd {
538538
basic_array(const array<size_type, 1>& lengths);
539539

540540
basic_array(const_pointer array, size_type length) {
541-
if (array == null) __throw_argument_null_exception(__FILE__, __LINE__, __func__);
541+
if (array == null) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_null);
542542
data_->items = base_type {array, array + length};
543543
data_->upper_bound[0] = data_->items.size() - 1;
544544
}

src/xtd.core/include/xtd/collections/generic/enumerator.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#pragma once
55
#include "ienumerator.hpp"
66
#define __XTD_CORE_INTERNAL__
7-
#include "../../internal/__external_exceptions.hpp"
7+
#include "../../helpers/throw_helper.hpp"
88
#undef __XTD_CORE_INTERNAL__
99
#include "../../ptr.hpp"
1010
#include "../../static.hpp"
@@ -121,14 +121,14 @@ namespace xtd {
121121
explicit internal_enumerator(const collection_t& items, const vertion_t* current_version) : items_(items), version_(current_version ? *current_version : vertion_t {}), current_version_(current_version) {}
122122

123123
const value_type& current() const override {
124-
if (current_version_ && version_ != *current_version_) __throw_invalid_operation_exception("Collection was modified; enumeration operation may not execute.", __FILE__, __LINE__, __func__);
124+
if (current_version_ && version_ != *current_version_) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
125125
if (iterator_ != items_.cend()) return *iterator_;
126126
static auto default_value_type = value_type {};
127127
return default_value_type;
128128
}
129129

130130
bool move_next() override {
131-
if (current_version_ && version_ != *current_version_) __throw_invalid_operation_exception("Collection was modified; enumeration operation may not execute.", __FILE__, __LINE__, __func__);
131+
if (current_version_ && version_ != *current_version_) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation, "Collection was modified; enumeration operation may not execute.");
132132
if (!reset_) return ++iterator_ != items_.cend();
133133
reset_ = false;
134134
iterator_ = items_.cbegin();

src/xtd.core/include/xtd/collections/object_model/read_only_collection.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#pragma once
55
#include "../generic/ilist.hpp"
66
#define __XTD_CORE_INTERNAL__
7-
#include "../../internal/__external_exceptions.hpp"
7+
#include "../../helpers/throw_helper.hpp"
88
#undef __XTD_CORE_INTERNAL__
99
#include "../../size.hpp"
1010
#include <limits>
@@ -51,7 +51,7 @@ namespace xtd {
5151
generic::enumerator<list_type_t> get_enumerator() const noexcept {
5252
class empty_enumerator : public generic::ienumerator<list_type_t> {
5353
public:
54-
const list_type_t& current() const override {__throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);}
54+
const list_type_t& current() const override {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);}
5555
bool move_next() override {return false;}
5656
void reset() override {}
5757
private:
@@ -60,8 +60,8 @@ namespace xtd {
6060
}
6161
xtd::size index_of(const list_type_t& item) const noexcept override {return npos;}
6262

63-
const list_type_t& operator [](xtd::size index) const override {__throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);}
64-
list_type_t& operator [](xtd::size index) override {__throw_argument_out_of_range_exception(__FILE__, __LINE__, __func__);}
63+
const list_type_t& operator [](xtd::size index) const override {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);}
64+
list_type_t& operator [](xtd::size index) override {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);}
6565

6666
private:
6767
bool is_fixed_size() const noexcept override {return false;}
@@ -254,7 +254,7 @@ namespace xtd {
254254
/// @}
255255

256256
private:
257-
reference operator [](size_type index) override {__throw_invalid_operation_exception(__FILE__, __LINE__, __func__);}
257+
reference operator [](size_type index) override {xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::invalid_operation);}
258258
bool is_fixed_size() const noexcept override {return false;}
259259
bool is_read_only() const noexcept override {return false;}
260260
bool is_synchronized() const noexcept override {return false;}

src/xtd.core/include/xtd/internal/__external_exceptions.hpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)