python try raise for warnings

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

python try raise for warnings

ChetMeinzer
Is it possible to define my own type of error and raise that based on spss syntax output?
For example, when a file is open on another computer and spss attempts to save over it, I’m getting the ‘_1’.  
But, I need this warning to trigger a ‘break’ or error that ends the ‘try:’

Also, is there a way around this all together.

Class WarningSave(Exception):
        def __init__(self, value):
                self.value = value
        def __str__(self):
                return repr(self.value)
Reply | Threaded
Open this post in threaded view
|

Re: python try raise for warnings

Albert-Jan Roskam
----- Original Message -----

> From: ChetMeinzer <[hidden email]>
> To: [hidden email]
> Cc:
> Sent: Wednesday, June 26, 2013 5:58 PM
> Subject: [SPSSX-L] python try raise for warnings
>
> Is it possible to define my own type of error and raise that based on spss
> syntax output?
> For example, when a file is open on another computer and spss attempts to
> save over it, I’m getting the ‘_1’.
> But, I need this warning to trigger a ‘break’ or error that ends the ‘try:’
>
> Also, is there a way around this all together.
>
> Class WarningSave(Exception):
> �  �  �  �  def __init__(self, value):
> �  �  �  �  �  �  �  �  self.value = value
> �  �  �  �  def __str__(self):
> �  �  �  �  �  �  �  �  return repr(self.value)

No need to write an own error class. Probably this will do the trick:

try:
� � �  with open(filename, "wb") as f:
� � � � � � �  pass # add code here, but as little� code as possible
except IOError, e:
� � �  raise Exception(e)
else:
� � �  pass # optionally add code here that might also raise an IOError that you don't want to catch
finally:
� �  pass # optionally add code that you ALWAYS want to run.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD