Mercurial > hg > orthanc-book
annotate Sphinx/source/plugins/python/exception.py @ 1113:a588960a72e5 default tip
spelling
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 28 Oct 2024 09:23:08 +0100 |
parents | 56d48f6e52cc |
children |
rev | line source |
---|---|
747
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 import orthanc |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 def OnChange(changeType, level, resource): |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 if changeType == orthanc.ChangeType.ORTHANC_STARTED: |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 try: |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 print(orthanc.RestApiGet('/nope')) |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 except ValueError as e: |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 # Raised in releases <= 3.2 of the plugin (doesn't occur in releases >= 3.3) |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 print(e) |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 except orthanc.OrthancException as e: |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 # Raised in releases >= 3.3 of the plugin (fails with releases <= 3.2) |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 print(e) |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 print(e.args[0]) # Error code of Orthanc (cf. "orthanc.ErrorCode" enumeration) |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 print(e.args[1]) # Description of the error |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 print(e.args[0] == orthanc.ErrorCode.UNKNOWN_RESOURCE) # Returns "True" |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 |
56d48f6e52cc
catching exceptions in python plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 orthanc.RegisterOnChangeCallback(OnChange) |