From a9323432d0840e1be7e936eeb4ce8430a2b0bb9b Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 4 Jan 2021 11:34:48 +0000 Subject: [PATCH] Change JSBSim MatrixException base type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make this exception inherit std::runtime_exception, so that it’s caught by the ‘normal’ exception cases in FG boostrap.cxx This is the only exception I can find in the codebase, which does not inherit from either std::exception or std::string, so this is to fix ‘unknown exception’ errors reported in the wild. Sentry-Id: FLIGHTGEAR-1C --- src/FDM/JSBSim/math/FGMatrix33.cpp | 8 ++------ src/FDM/JSBSim/math/FGMatrix33.h | 7 +++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/FDM/JSBSim/math/FGMatrix33.cpp b/src/FDM/JSBSim/math/FGMatrix33.cpp index 2e2297eca..051aecf7f 100644 --- a/src/FDM/JSBSim/math/FGMatrix33.cpp +++ b/src/FDM/JSBSim/math/FGMatrix33.cpp @@ -437,9 +437,7 @@ FGMatrix33 FGMatrix33::operator/(const double scalar) const Quot.data[5] = data[5] * tmp; Quot.data[8] = data[8] * tmp; } else { - MatrixException mE; - mE.Message = "Attempt to divide by zero in method FGMatrix33::operator/(const double scalar)"; - throw mE; + throw MatrixException{"Attempt to divide by zero in method FGMatrix33::operator/(const double scalar)"}; } return Quot; } @@ -460,9 +458,7 @@ FGMatrix33& FGMatrix33::operator/=(const double scalar) data[5] *= tmp; data[8] *= tmp; } else { - MatrixException mE; - mE.Message = "Attempt to divide by zero in method FGMatrix33::operator/=(const double scalar)"; - throw mE; + throw MatrixException{"Attempt to divide by zero in method FGMatrix33::operator/=(const double scalar)"}; } return *this; } diff --git a/src/FDM/JSBSim/math/FGMatrix33.h b/src/FDM/JSBSim/math/FGMatrix33.h index 8e699475d..85fde1ea4 100644 --- a/src/FDM/JSBSim/math/FGMatrix33.h +++ b/src/FDM/JSBSim/math/FGMatrix33.h @@ -42,6 +42,7 @@ INCLUDES #include #include +#include #include "FGColumnVector3.h" @@ -64,10 +65,12 @@ CLASS DOCUMENTATION DECLARATION: MatrixException %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -class MatrixException //: public FGJSBBase +// changed by James to inherit std::runtime_error, so that if this +// gets thrown, we can actually catch it. +class MatrixException : public std::runtime_error { public: - std::string Message; + MatrixException(const std::string& msg) : std::runtime_error{msg} { } }; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%