comparison 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
comparison
equal deleted inserted replaced
746:b2b1ba11faaa 747:56d48f6e52cc
1 import orthanc
2
3 def OnChange(changeType, level, resource):
4 if changeType == orthanc.ChangeType.ORTHANC_STARTED:
5 try:
6 print(orthanc.RestApiGet('/nope'))
7 except ValueError as e:
8 # Raised in releases <= 3.2 of the plugin (doesn't occur in releases >= 3.3)
9 print(e)
10 except orthanc.OrthancException as e:
11 # Raised in releases >= 3.3 of the plugin (fails with releases <= 3.2)
12 print(e)
13 print(e.args[0]) # Error code of Orthanc (cf. "orthanc.ErrorCode" enumeration)
14 print(e.args[1]) # Description of the error
15 print(e.args[0] == orthanc.ErrorCode.UNKNOWN_RESOURCE) # Returns "True"
16
17 orthanc.RegisterOnChangeCallback(OnChange)