Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exceptions thrown by FGFunction and caught by FGAerodynamics #1152

Merged
merged 2 commits into from
Sep 11, 2024

Conversation

bcoconni
Copy link
Member

@bcoconni bcoconni commented Sep 7, 2024

The class FGAerodynamics currently catches std::string exceptions thrown by the constructor of FGFunction. However FGFunction is now throwing a mix of exceptions deriving from both std::string and JSBSim::BaseException, so FGAerodynamics is no longer catching all exceptions thrown by the constructor of FGFunction.

This PR is changing:

  • the remaining std::string exceptions in FGFunction to JSBSim::BaseException
  • the format of exceptions caught by FGAerodynamics from std::string to JSBSim::BaseException.

Also the try/catch block in FGAerodynamics is simplified in the process. Currently the code looks like:

if (condition) {
  try {
    function1 = new FGFunction();
  }
  catch (const string& str) {
    log << "Fatal error: " << str;
  }
}
else {
  try {
    function2 = new FGFunction();
  }
  catch (const string& str) {
    log << "Fatal error: " << str;
  }
}

This PR avoids the duplication of the try/catch block by moving the if/else condition into the try block:

try {
  if (condition) {
    function1 = new FGFunction();
  } else {
    function2 = new FGFunction();
  }
}
catch (const BaseException& e) {
    log << "Fatal error: " << e.what();
}

Copy link

codecov bot commented Sep 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Project coverage is 25.13%. Comparing base (e607c27) to head (aa97d04).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/math/FGFunction.cpp 0.00% 13 Missing ⚠️
src/models/FGAerodynamics.cpp 0.00% 7 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1152   +/-   ##
=======================================
  Coverage   25.12%   25.13%           
=======================================
  Files         170      170           
  Lines       18337    18330    -7     
=======================================
  Hits         4608     4608           
+ Misses      13729    13722    -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seanmcleod
Copy link
Member

Looks good.

@bcoconni bcoconni merged commit 8e4803b into JSBSim-Team:master Sep 11, 2024
30 checks passed
@bcoconni bcoconni deleted the function_exceptions branch September 11, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants