Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/50870 )

Change subject: python: Handle exceptions in gem5py.cc.
......................................................................

python: Handle exceptions in gem5py.cc.

If an exception is thrown in python, it will emerge in c++ as a
py::error_already_set exception. If it was a SystemExit exception, we
should handle that gracefully and exit with the requested code. If it
was something else, we should print what() so the user has more info
about what went wrong.

Change-Id: I85a94b47865a49f9fbebfc22272249a5f0f59bf5
---
M src/python/gem5py.cc
1 file changed, 9 insertions(+), 1 deletion(-)



diff --git a/src/python/gem5py.cc b/src/python/gem5py.cc
index f2d8759..9b59a03 100644
--- a/src/python/gem5py.cc
+++ b/src/python/gem5py.cc
@@ -76,7 +76,15 @@
         py_argv.append(argv[i]);

     // Actually call the script.
-    py::eval_file(argv[1]);
+    try {
+        py::eval_file(argv[1]);
+    } catch (py::error_already_set &e) {
+        if (e.matches(PyExc_SystemExit))
+            return e.value().attr("code").cast<int>();
+
+        std::cerr << e.what();
+        return 1;
+    }

     return 0;
 }

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50870
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I85a94b47865a49f9fbebfc22272249a5f0f59bf5
Gerrit-Change-Number: 50870
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to