470,641 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

try

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"

May 16 '07 #1
3 1519
HMS Surprise wrote:
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

May 16 '07 #2
On May 16, 4:22 pm, Robert Kern <robert.k...@gmail.comwrote:
HMS Surprise wrote:
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"
--
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

May 17 '07 #3
On May 17, 7:51 am, Dustan <DustanGro...@gmail.comwrote:
On May 16, 4:22 pm, Robert Kern <robert.k...@gmail.comwrote:
HMS Surprise wrote:
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"
--
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
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

May 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.