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

Make Meep C++ errors visible in Jupyter notebooks #953

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions python/meep.i
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,15 @@ meep::volume_list *make_volume_list(const meep::volume &v, int c,
double *total
};

%exception {
try {
$action
} catch (std::runtime_error &e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
SWIG_fail;
}
}

// Tells Python to take ownership of the h5file* this function returns so that
// it gets garbage collected and the file gets closed.
%newobject meep::fields::open_h5file;
Expand Down
14 changes: 10 additions & 4 deletions src/mympi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,20 @@ double wall_time(void) {
void abort(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "meep: ");
vfprintf(stderr, fmt, ap);
char *s;
vasprintf(&s, fmt, ap);
va_end(ap);
if (fmt[strlen(fmt) - 1] != '\n') fputc('\n', stderr); // force newline
// Make a std::string to support older compilers (std::runtime_error(char *) was added in C++11)
std::string error_msg(s);
free(s);
if (count_processors() == 1) {
throw runtime_error("meep: " + error_msg);
}
#ifdef HAVE_MPI
fprintf(stderr, "meep: %s", error_msg.c_str());
if (fmt[strlen(fmt) - 1] != '\n') fputc('\n', stderr); // force newline
MPI_Abort(MPI_COMM_WORLD, 1);
#endif
exit(1);
}

void send(int from, int to, double *data, int size) {
Expand Down