Mercurial > hg > orthanc-book
annotate Sphinx/source/plugins/python/exception.py @ 789:2f70f622059b
added odbc tip
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 24 Nov 2021 15:30:29 +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) |