Commit 0980f220 authored by Martin Marinov's avatar Martin Marinov
Browse files

Replaced the ReForm::Outcome based exception object with...

Replaced the ReForm::Outcome based exception object with Base/COMISO/IGM/ReForm::Error. This allow ReForm-independent compilation and usage of Base/COMISO/IGM. Also improved exception throwing in general, including safety, readibility, debugging, etc. No behavior changes.

[git-p4: depot-paths = "//ReForm/ReForm/main/Base/": change = 13023]
parent 1157d2ba
......@@ -9,6 +9,7 @@
// and manner of such use.
#include "DebUtils.hh"
#include "Base/Utils/ThrowError.hh"
#ifdef DEB_ON
......@@ -1047,6 +1048,13 @@ Stream& operator<<(Stream& _ds, const Command& _co)
return _ds.print(_co);
}
Stream& operator<<(Stream& _ds, const ThrowInfo& _thrw_info)
{
_ds << "thrown by " << _thrw_info.fnct_ << "() in " << _thrw_info.modl_ <<
" file " << _thrw_info.file_ << " @ line " << _thrw_info.line_;
return _ds;
}
// ==================================================
// Controller member funcs (currently all static)
// ==================================================
......
// (C) Copyright 2015 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#include "BaseError.hh"
namespace Base {
static const char* ERROR_MESSAGE[] =
{
#define DEFINE_ERROR(CODE, MSG) MSG,
#include "BaseErrorInc.hh"
#undef DEFINE_ERROR
};
const char* Error::message() const { return ERROR_MESSAGE[idx_]; }
}//namespace Base
// (C) Copyright 2015 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifndef BASE_ERROR_HH_INCLUDED
#define BASE_ERROR_HH_INCLUDED
#include <Base/Utils/ThrowError.hh>
namespace Base {
class Error
{
public:
enum Index
{
#define DEFINE_ERROR(CODE, MSG) CODE,
#include <Base/Utils/BaseErrorInc.hh>
#undef DEFINE_ERROR
};
public:
//! Constructor.
Error(const Index _idx) : idx_((int)_idx) {}
// ! Get the outcome error index
int index() const { return (int)idx_; }
//! Return the error message
virtual const char* message() const;
template <typename IndexT>
bool operator==(const IndexT _idx) const { return (int)_idx == idx_; }
protected:
int idx_;
protected:
//! Constructor.
Error(const int _idx) : idx_(_idx) {}
};
}//namespace BASE
#define BASE_THROW_ERROR(INDEX) { THROW_ERROR_MODULE(Base, INDEX); }
#define BASE_THROW_ERROR_if(COND, INDEX) { if (COND) THROW_ERROR(INDEX); }
#define BASE_THROW_ERROR_TODO(MSG) { THROW_ERROR_TODO_MODULE(Base, MSG); }
#define BASE_THROW_ERROR_TODO_if(COND, MSG) { if (COND) THROW_ERROR_TODO(MSG); }
#endif//BASE_ERROR_HH_INCLUDED
// (C) Copyright 2014 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
//!\ReForm_SDK
#ifndef DEFINE_ERROR
#error This file should not be included directly, include the corresponding Outcome/Error header instead
#endif
DEFINE_ERROR(TODO, "TODO: Undefined error message")
set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/OutcomeUtils.hh
${CMAKE_CURRENT_SOURCE_DIR}/BaseError.hh
${CMAKE_CURRENT_SOURCE_DIR}/BaseErrorInc.hh
${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.hh
${CMAKE_CURRENT_SOURCE_DIR}/ThrowError.hh
PARENT_SCOPE
)
set(my_sources
${CMAKE_CURRENT_SOURCE_DIR}/BaseError.cc
${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.cc
PARENT_SCOPE
)
// (C) Copyright 2014 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk, Inc., and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of this information by anyone other than authorized
// employees of Autodesk, Inc. is granted only under a written
// non-disclosure agreement, expressly prescribing the scope
// and manner of such use.
#ifndef REFORM_OUTCOMEUTILS_HH_INCLUDED
#define REFORM_OUTCOMEUTILS_HH_INCLUDED
#include <ReForm/Base/Outcome.hh>
#include <Base/Debug/DebOut.hh>
#include <exception>
// We are throwing Outcome::ErrorIndex for now. Throwing an enum is distinct
// from throwing an int so we should be safe here, but throwing an Outcome
// proper would enable a breakpoint in the Outcome constructor being
// exercised by the THROW.
#define THROW_OUTCOME(ERROR_INDEX) { throw ReForm::Outcome::ERROR_INDEX; }
#define THROW_OUTCOME_if(COND, ERROR_INDEX) \
{ if (COND) THROW_OUTCOME(ERROR_INDEX); }
#define DEB_throw_outcome_if(COND, ERROR_MSG) \
{ if (COND) { DEB_error(ERROR_MSG); THROW_OUTCOME(TODO); } }
#define CATCH_OUTCOME(OC) catch (ReForm::Outcome::ErrorIndex& OC)
#define RETHROW_OUTCOME(EXPR) (EXPR).rethrow()
#define RETURN_OUTCOME(EXPR) \
{ const auto oc = (EXPR); if (!oc.ok()) return oc; }
// TODO: should CLEAR_EXPR be in a try block as well?
#define OUTCOME_CALL_WRAP(MAIN_EXPR, CLEAR_EXPR) \
DEB_enter_func; \
try \
{ \
MAIN_EXPR; \
} \
CATCH_OUTCOME(oc) \
{ \
DEB_warning(1, "ReForm outcome exception: " << Outcome(oc).error_message()); \
CLEAR_EXPR; \
return oc; \
} \
catch (const std::exception& exc) \
{ \
DEB_error("Unspecified standard exception " \
"[unexpected, either bug, bad data or out of memory]: " << exc.what()); \
CLEAR_EXPR; \
return Outcome::UNSPECIFIED_STD_EXCEPTION; \
} \
catch (...) \
{ \
DEB_error("Unspecified general exception [unexpected, most likely a bug]"); \
CLEAR_EXPR; \
return Outcome::UNSPECIFIED_EXCEPTION; \
} \
DEB_line(7, "Outcome call successful"); \
return Outcome();
#define OUTCOME_CALL_WRAP_NO_CLEAR(MAIN_EXPR) OUTCOME_CALL_WRAP(MAIN_EXPR, ([]{}))
#endif//REFORM_OUTCOMEUTILS_HH_INCLUDED
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment