Skip to content
Snippets Groups Projects
Commit 0595d1b9 authored by Boman Romain's avatar Boman Romain
Browse files

better exception handling

parent 5d04649d
No related branches found
No related tags found
No related merge requests found
Pipeline #7086 passed
...@@ -63,8 +63,10 @@ class Window(QWidget, Ui_Form): ...@@ -63,8 +63,10 @@ class Window(QWidget, Ui_Form):
def run_simulation(testname): def run_simulation(testname):
"""Runs a python file """Runs a python file
""" """
# thanks to the "compile" command, the filename appears in the stack
exec(open(testname, encoding='utf-8').read(), # trace in case of errors
script = open(testname, encoding='utf-8').read()
exec(compile(script, testname, 'exec'),
{'__file__': testname, '__name__':'__main__'}) {'__file__': testname, '__name__':'__main__'})
...@@ -155,13 +157,15 @@ if __name__ == "__main__": ...@@ -155,13 +157,15 @@ if __name__ == "__main__":
workspace = win.wrkspLineEdit.text() workspace = win.wrkspLineEdit.text()
action = win.action action = win.action
testname = win.inpFileLineEdit.text() testname = win.inpFileLineEdit.text()
gui = True
else: else:
workspace = None workspace = None
action = 'run' action = 'run'
testname = os.path.abspath(args.file) testname = os.path.abspath(args.file)
gui = False
# run the simulation or display results # run the simulation or display results
print(f'action = {action}') print(f'action = {action}')
if action=='run' or action=='post': if action=='run' or action=='post':
testname = os.path.normcase(testname) # F:/ => f:/ on Windows testname = os.path.normcase(testname) # F:/ => f:/ on Windows
...@@ -186,7 +190,14 @@ if __name__ == "__main__": ...@@ -186,7 +190,14 @@ if __name__ == "__main__":
tee = cxxfem.Tee('stdout.txt') # split streams tee = cxxfem.Tee('stdout.txt') # split streams
if action == 'run': try:
run_simulation(testname) if action == 'run':
elif action == 'post': run_simulation(testname)
view_results() elif action == 'post':
view_results()
except Exception as err:
print(f'\n** ERROR: {err}\n')
import traceback
traceback.print_exc()
if gui:
input('\nPress <ENTER> to continue...\n')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment