Hi all,

Sorry in advance if that is a rookie python question... I am trying to improve my error handling to prevent run time errors from stopping my algo in live / Alpha Streams, while still logging informative messages in case errors are encountered.

I have tried different syntaxes:

Syntax 1

try:

   ...

except ValueError:

   self.Log("Some hardcoded message mentioning a ValueError")

Syntax 2

try:

   ...

except:

   self.Log("Some hardcoded message")

Syntax 3

try:

   ...

except Exception as ex:

   self.Log("An exception of type " + str(type(ex).__name__) + " occurred. Arguments: " + str(ex.args) )

 

I have found that syntax 3 does not work, i.e. in that case the ValueError still triggers a run time error, stopping the execution of the algo.

Syntax 1 and syntax 2 are effective, in the sense that the error no longer stops the algo. However they are not ideal because:

- For various reasons, it is impractical or even impossible for me to predict all the types of errors that may be encountered (I cannot be sure they will be only ValueError)

- On the other hand, catching all exceptions without extracting information about the error is not informative enough (and firmly against good coding practices it seems)

 

Any advice would be greatly appreciated

Thanks in advance