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):
def run_simulation(testname):
"""Runs a python file
"""
exec(open(testname, encoding='utf-8').read(),
# thanks to the "compile" command, the filename appears in the stack
# trace in case of errors
script = open(testname, encoding='utf-8').read()
exec(compile(script, testname, 'exec'),
{'__file__': testname, '__name__':'__main__'})
......@@ -155,13 +157,15 @@ if __name__ == "__main__":
workspace = win.wrkspLineEdit.text()
action = win.action
testname = win.inpFileLineEdit.text()
gui = True
else:
workspace = None
action = 'run'
testname = os.path.abspath(args.file)
gui = False
# run the simulation or display results
print(f'action = {action}')
if action=='run' or action=='post':
testname = os.path.normcase(testname) # F:/ => f:/ on Windows
......@@ -186,7 +190,14 @@ if __name__ == "__main__":
tee = cxxfem.Tee('stdout.txt') # split streams
if action == 'run':
run_simulation(testname)
elif action == 'post':
view_results()
try:
if action == 'run':
run_simulation(testname)
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