Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion components/eamxx/src/mct_coupling/scream_cxx_f90_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,23 @@ void fpe_guard_wrapper (const Lambda& f) {
try {
f();
} catch (std::exception &e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to change this to catch (...) for greater generality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can do that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but I want to print the exception message.

Copy link
Contributor Author

@bartgol bartgol Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do a rethrow, then add catch(...) underneath That didn't work, so I'm duplicating a bit the code to cover both needs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that work? Or do you need to nest try blocks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this, but you might consider nesting try-catch blocks to avoid redundant code:

  try {
    try {
      throw std::exception();
    } catch (const std::exception& e) {
      printf("hi\n");
      throw;
    }
  } catch (...) {
    printf("hello\n");
  }

// Print exception msg, then call MPI_Abort
fprintf(stderr, "%s\n", e.what());

// Get raw comm before cleaning up singleton
auto& c = ScreamContext::singleton();
auto raw_comm = c.get<ekat::Comm>().mpi_comm();
c.clean_up();

MPI_Abort (raw_comm,1);
} catch (...) {

// Get raw comm before cleaning up singleton
auto& c = ScreamContext::singleton();
auto raw_comm = c.get<ekat::Comm>().mpi_comm();
c.clean_up();
throw;

MPI_Abort (raw_comm,1);
}

// Restore the FPE flag as it was when control was handed to us.
Expand Down