try

H

HMS Surprise

I read in the ref man that try-except-finally did not work in earlier
versions, I am using jython 2.2. Does this imply that try-except
without finally does not work either? I get a syntax error on the else
below. Some of the functions embedded in the try section try to
convert strings to ints, etc and may fail on bad data, thus try seemed
like a good start for a workaround.

Thanks,

jh


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def restoreDevice(self, deviceId, closeTime = time()):
self.logon()
try:
lst = self.getLastUpdatedDevice(deviceId)
lastUpdated = lst[0]
incidentId = lst[1]
print 'L', lastUpdated, 'I', incidentId
self.restore(incidentId, lastUpdated)
except:
else:
print "couldn't find incident"
 
R

Robert Kern

HMS said:
I read in the ref man that try-except-finally did not work in earlier
versions, I am using jython 2.2. Does this imply that try-except
without finally does not work either? I get a syntax error on the else
below. Some of the functions embedded in the try section try to
convert strings to ints, etc and may fail on bad data, thus try seemed
like a good start for a workaround.

Thanks,

jh


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def restoreDevice(self, deviceId, closeTime = time()):
self.logon()
try:
lst = self.getLastUpdatedDevice(deviceId)
lastUpdated = lst[0]
incidentId = lst[1]
print 'L', lastUpdated, 'I', incidentId
self.restore(incidentId, lastUpdated)
except:
else:
print "couldn't find incident"

The except: block still needs something in it, even if it is just "pass".

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
D

Dustan

HMS said:
I read in the ref man that try-except-finally did not work in earlier
versions, I am using jython 2.2. Does this imply that try-except
without finally does not work either? I get a syntax error on the else
below. Some of the functions embedded in the try section try to
convert strings to ints, etc and may fail on bad data, thus try seemed
like a good start for a workaround.

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def restoreDevice(self, deviceId, closeTime = time()):
self.logon()
try:
lst = self.getLastUpdatedDevice(deviceId)
lastUpdated = lst[0]
incidentId = lst[1]
print 'L', lastUpdated, 'I', incidentId
self.restore(incidentId, lastUpdated)
except:
else:
print "couldn't find incident"

The except: block still needs something in it, even if it is just "pass".

For sake of demonstration:

def restoreDevice(self, deviceId, closeTime = time()):
self.logon()
try:
lst = self.getLastUpdatedDevice(deviceId)
lastUpdated = lst[0]
incidentId = lst[1]
print 'L', lastUpdated, 'I', incidentId
self.restore(incidentId, lastUpdated)
except:
pass
else:
print "couldn't find incident"
 
H

HMS Surprise

HMS said:
I read in the ref man that try-except-finally did not work in earlier
versions, I am using jython 2.2. Does this imply that try-except
without finally does not work either? I get a syntax error on the else
below. Some of the functions embedded in the try section try to
convert strings to ints, etc and may fail on bad data, thus try seemed
like a good start for a workaround.
Thanks,
jh
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def restoreDevice(self, deviceId, closeTime = time()):
self.logon()
try:
lst = self.getLastUpdatedDevice(deviceId)
lastUpdated = lst[0]
incidentId = lst[1]
print 'L', lastUpdated, 'I', incidentId
self.restore(incidentId, lastUpdated)
except:
else:
print "couldn't find incident"
The except: block still needs something in it, even if it is just "pass".

For sake of demonstration:

def restoreDevice(self, deviceId, closeTime = time()):
self.logon()
try:
lst = self.getLastUpdatedDevice(deviceId)
lastUpdated = lst[0]
incidentId = lst[1]
print 'L', lastUpdated, 'I', incidentId
self.restore(incidentId, lastUpdated)
except:
pass
else:
print "couldn't find incident"
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Thanks folks. Found my error but I didn't know of pass option.....
Wanted to get back in earlier and state I found the error but Google
groups seemed to be down for half a day....

jvh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top