aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL
diff options
context:
space:
mode:
authorumarcor <unai.martinezcorral@ehu.eus>2021-06-20 01:02:59 +0200
committerumarcor <unai.martinezcorral@ehu.eus>2021-06-22 13:17:36 +0200
commit38571ce4ce5e1d594a7c55f5bb6f1514f1402329 (patch)
tree914dda852c9b662b07ebcc9249edee92334a9ae2 /pyGHDL
parent015f62d05b35466a6fbb5f33370d9615e028f9f0 (diff)
downloadghdl-38571ce4ce5e1d594a7c55f5bb6f1514f1402329.tar.gz
ghdl-38571ce4ce5e1d594a7c55f5bb6f1514f1402329.tar.bz2
ghdl-38571ce4ce5e1d594a7c55f5bb6f1514f1402329.zip
pyGHDL/cli/DOM: handle multiple exception types
Diffstat (limited to 'pyGHDL')
-rwxr-xr-xpyGHDL/cli/DOM.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/pyGHDL/cli/DOM.py b/pyGHDL/cli/DOM.py
index 1ab3d4321..2feb6aecd 100755
--- a/pyGHDL/cli/DOM.py
+++ b/pyGHDL/cli/DOM.py
@@ -7,15 +7,15 @@ from pathlib import Path
from pydecor import export
+from pyGHDL import GHDLBaseException
+from pyGHDL.libghdl import LibGHDLException
from pyGHDL.dom import NonStandard
+from pyGHDL.dom.Common import DOMException
+from pyGHDL.dom.formatting.prettyprint import PrettyPrint, PrettyPrintException
__all__ = []
__api__ = __all__
-from pyGHDL.dom.Common import DOMException
-
-from pyGHDL.dom.formatting.prettyprint import PrettyPrint, PrettyPrintException
-
@export
class Application:
@@ -40,6 +40,26 @@ class Application:
print("\n".join(buffer))
+def handleException(ex):
+ if isinstance(ex, PrettyPrintException):
+ print("PP:", ex)
+ return 5
+ elif isinstance(ex, DOMException):
+ print("DOM:", ex)
+ return 4
+ elif isinstance(ex, LibGHDLException):
+ print("LIB:", ex)
+ return 3
+ elif isinstance(ex, GHDLBaseException):
+ print("GHDL:", ex)
+ return 2
+ else:
+ print(
+ "Fatal: An unhandled exception has reached to the top-most exception handler."
+ )
+ return 1
+
+
def main(items=argv[1:]):
_exitcode = 0
@@ -53,11 +73,8 @@ def main(items=argv[1:]):
app = Application()
app.addFile(Path(item), "default_lib")
app.prettyPrint()
- except DOMException as ex:
- print("DOM:", ex)
- except PrettyPrintException as ex:
- print("PP:", ex)
- _exitcode = 1
+ except Exception as ex:
+ _exitcode = handleException(ex)
return _exitcode