XBT_INFO("Option %s has been renamed to %s. Consider switching.", name.c_str(), res->get_key().c_str());
return res;
} else {
- THROWF(not_found_error, 0, "Bad config key: %s", name.c_str());
+ throw std::out_of_range("Bad config key: " + name);
}
}
}
INFO("Access to a non-existant entry");
- REQUIRE_THROWS_MATCHES(
- simgrid::config::set_parse("color:blue"), xbt_ex,
- Catch::Matchers::Predicate<xbt_ex>([](xbt_ex const& e) { return e.category == not_found_error; },
- "category not_found_error"));
+ REQUIRE_THROWS_AS(simgrid::config::set_parse("color:blue"), std::out_of_range);
simgrid::config::finalize();
simgrid_config = temp;
#include "xbt/log.h"
#include "xbt/mallocator.h"
#include "xbt/str.h"
+#include "xbt/string.hpp"
#include <cstdio>
#include <cstring>
* @param key_len the size of the @a key
* @return the data that we are looking for
*
- * Search the given @a key. Throws not_found_error when not found.
+ * Search the given @a key. Throws std::out_of_range when not found.
*/
void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
{
}
if (current == nullptr)
- THROWF(not_found_error, 0, "key %.*s not found", key_len, key);
+ throw std::out_of_range(simgrid::xbt::string_printf("key %.*s not found", key_len, key));
return current->content;
}
* @param key the key to find data
* @return the data that we are looking for
*
- * Search the given @a key. Throws not_found_error when not found.
+ * Search the given @a key. Throws std::out_of_range when not found.
* Check xbt_dict_get_or_null() for a version returning nullptr without exception when not found.
*/
void *xbt_dict_get(xbt_dict_t dict, const char *key)
* @param key the key to find data
* @return the s_xbt_dictelm_t that we are looking for
*
- * Search the given @a key. Throws not_found_error when not found.
+ * Search the given @a key. Throws std::out_of_range when not found.
* Check xbt_dict_get_or_null() for a version returning nullptr without exception when not found.
*/
xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key)
xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key);
if (current == nullptr)
- THROWF(not_found_error, 0, "key %s not found", key);
+ throw std::out_of_range(simgrid::xbt::string_printf("key %s not found", key));
return current;
}
* @param key the key of the data to be removed
* @param key_len the size of the @a key
*
- * Remove the entry associated with the given @a key (throws not_found)
+ * Remove the entry associated with the given @a key (throws std::out_of_range)
*/
void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len)
{
}
if (current == nullptr)
- THROWF(not_found_error, 0, "key %.*s not found", key_len, key);
+ throw std::out_of_range(simgrid::xbt::string_printf("key %.*s not found", key_len, key));
else {
if (previous != nullptr) {
previous->next = current->next;
#define STR(str) ((str) ? (str) : "(null)")
-#define REQUIRE_THROWS_XBT_EX(...) \
- REQUIRE_THROWS_MATCHES((__VA_ARGS__), xbt_ex, Catch::Matchers::Predicate<xbt_ex>( \
- [](xbt_ex const& e) { return e.category == not_found_error; }, \
- "category not_found_error"))
-
static constexpr int NB_ELM = 20000;
static constexpr int SIZEOFKEY = 1024;
static void search_not_found(xbt_dict_t head, const char* data)
{
INFO("Search " << STR(data) << " (expected not to be found)");
- REQUIRE_THROWS_XBT_EX(data = (const char*)xbt_dict_get(head, data));
+ REQUIRE_THROWS_AS(xbt_dict_get(head, data), std::out_of_range);
}
static void count(xbt_dict_t dict, int length)
INFO("Traversal and search the empty dictionary");
xbt_dict_t head = xbt_dict_new_homogeneous(&free);
traverse(head);
- REQUIRE_THROWS_XBT_EX(debugged_remove(head, "12346"));
+ REQUIRE_THROWS_AS(debugged_remove(head, "12346"), std::out_of_range);
xbt_dict_free(&head);
INFO("Traverse the full dictionary");
xbt_dict_t head = new_fixture();
count(head, 7);
INFO("Remove non existing data");
- REQUIRE_THROWS_XBT_EX(debugged_remove(head, "Does not exist"));
+ REQUIRE_THROWS_AS(debugged_remove(head, "Does not exist"), std::out_of_range);
traverse(head);
xbt_dict_free(&head);
debugged_remove(head, "123456");
traverse(head);
count(head, 3);
- REQUIRE_THROWS_XBT_EX(debugged_remove(head, "12346"));
+ REQUIRE_THROWS_AS(debugged_remove(head, "12346"), std::out_of_range);
traverse(head);
debugged_remove(head, "1234");
traverse(head);
traverse(head);
debugged_remove(head, "123");
traverse(head);
- REQUIRE_THROWS_XBT_EX(debugged_remove(head, "12346"));
+ REQUIRE_THROWS_AS(debugged_remove(head, "12346"), std::out_of_range);
traverse(head);
INFO("Free dict, create new fresh one, and then reset the dict");
#include "xbt/ex.h"
#include "xbt/log.h"
#include "xbt/misc.h"
+#include "xbt/string.hpp"
#include "xbt/sysdep.h"
#include <sys/types.h>
static inline void _check_inbound_idx(xbt_dynar_t dynar, int idx)
{
if (idx < 0 || idx >= static_cast<int>(dynar->used)) {
- THROWF(bound_error, idx, "dynar is not that long. You asked %d, but it's only %lu long",
- idx, static_cast<unsigned long>(dynar->used));
+ throw std::out_of_range(simgrid::xbt::string_printf("dynar is not that long. You asked %d, but it's only %lu long",
+ idx, static_cast<unsigned long>(dynar->used)));
}
}
static inline void _check_populated_dynar(xbt_dynar_t dynar)
{
if (dynar->used == 0) {
- THROWF(bound_error, 0, "dynar %p is empty", dynar);
+ throw std::out_of_range(simgrid::xbt::string_printf("dynar %p is empty", dynar));
}
}
* }
* @endcode
*
- * Raises not_found_error if not found. If you have less than 2 millions elements, you probably want to use
- * #xbt_dynar_search_or_negative() instead, so that you don't have to TRY/CATCH on element not found.
+ * Raises std::out_of_range if not found. If you have less than 2 millions elements, you probably want to use
+ * #xbt_dynar_search_or_negative() instead, so that you don't have to try/catch on element not found.
*/
unsigned int xbt_dynar_search(xbt_dynar_t const dynar, void* const elem)
{
return it;
}
- THROWF(not_found_error, 0, "Element %p not part of dynar %p", elem, dynar);
+ throw std::out_of_range(simgrid::xbt::string_printf("Element %p not part of dynar %p", elem, dynar));
}
/** @brief Returns the position of the element in the dynar (or -1 if not found)