[WIP] Exception Generator function for implementing "from_rcl_error" (#678)
* Created function to generate exception objects Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * Created function to generate exception objects Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * Fixed typo Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * Fixed typo Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * Throw exceptions not created by ret Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * Throw exceptions not created by ret Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * convert throw_from_rcl_error to use from_rcl_error Mostly just a convenience function Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * Updated .gitignore Please ignore Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * Re-ordered functions to allow compilation Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * Revert "Updated .gitignore" This reverts commit bee0ee13ce687bc56bdc7ad1e8382506d9aef428. Signed-off-by: Jacob Hassold <jhassold@dcscorp.com> * restore .gitignore to original state Signed-off-by: Shane Loretz <sloretz@osrfoundation.org> * oops, actually restore .gitignore Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
This commit is contained in:
parent
68d0ac1e61
commit
713dd0c184
1 changed files with 21 additions and 7 deletions
|
@ -39,8 +39,8 @@ NameValidationError::format_error(
|
|||
return msg;
|
||||
}
|
||||
|
||||
void
|
||||
throw_from_rcl_error(
|
||||
std::exception_ptr
|
||||
from_rcl_error(
|
||||
rcl_ret_t ret,
|
||||
const std::string & prefix,
|
||||
const rcl_error_state_t * error_state,
|
||||
|
@ -55,9 +55,9 @@ throw_from_rcl_error(
|
|||
if (!error_state) {
|
||||
throw std::runtime_error("rcl error state is not set");
|
||||
}
|
||||
std::string formated_prefix = prefix;
|
||||
std::string formatted_prefix = prefix;
|
||||
if (!prefix.empty()) {
|
||||
formated_prefix += ": ";
|
||||
formatted_prefix += ": ";
|
||||
}
|
||||
RCLErrorBase base_exc(ret, error_state);
|
||||
if (reset_error) {
|
||||
|
@ -65,14 +65,28 @@ throw_from_rcl_error(
|
|||
}
|
||||
switch (ret) {
|
||||
case RCL_RET_BAD_ALLOC:
|
||||
throw RCLBadAlloc(base_exc);
|
||||
return std::make_exception_ptr(RCLBadAlloc(base_exc));
|
||||
case RCL_RET_INVALID_ARGUMENT:
|
||||
throw RCLInvalidArgument(base_exc, formated_prefix);
|
||||
return std::make_exception_ptr(RCLInvalidArgument(base_exc, formatted_prefix));
|
||||
default:
|
||||
throw RCLError(base_exc, formated_prefix);
|
||||
return std::make_exception_ptr(RCLError(base_exc, formatted_prefix));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
throw_from_rcl_error(
|
||||
rcl_ret_t ret,
|
||||
const std::string & prefix,
|
||||
const rcl_error_state_t * error_state,
|
||||
void (* reset_error)())
|
||||
{
|
||||
// We expect this to either throw a standard error,
|
||||
// or to generate an error pointer (which is caught
|
||||
// in err, and immediately thrown)
|
||||
auto err = from_rcl_error(ret, prefix, error_state, reset_error);
|
||||
std::rethrow_exception(err);
|
||||
}
|
||||
|
||||
RCLErrorBase::RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state)
|
||||
: ret(ret), message(error_state->message), file(error_state->file), line(error_state->line_number),
|
||||
formatted_message(rcl_get_error_string().str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue