annotate Sphinx/source/plugins/python/exception.py @ 747:56d48f6e52cc

catching exceptions in python plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Aug 2021 18:29:38 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)