From: Robert W. B. <rb...@di...> - 2001-09-23 15:36:37
|
On Sun, 23 Sep 2001, Ype Kingma wrote: > Robert, > > >On Sat, 22 Sep 2001, Frank Cohen wrote: > >> Thanks for the great reply. Lots of useful information here. I would > >> appreciate seeing your example code too. > >> > >> Do I have it right that Jython can't catch Java exceptions? > > > >Actually, Jython does catch Java exceptions. e.g.: > > > >>>> import java > >>>> try: > >... raise java.lang.UnknownError, "Java error raised" > >>>> except java.lang.UnknownError: > >... print "Java exception caught" > >... > >Java exception caught > >>>> > > > >It catches it just the same if a Java class throws it. > > Could you try java.lang.OutOfMemError, too? It's already some versions > of jython ago that I could not catch it in actual out of memory situations. > > Ype. ------------------------------------ >>> import java >>> try: ... raise java.lang.OutOfMemoryError ... except java.lang.OutOfMemoryError: ... print "Caught" ... Caught >>> ------------------------------------ The above works, but I know it's not what you are getting at. The complication of the System.exit(-1) in Py.MemoryError(OutOfMemoryError t) (file org/python/core/Py.java) is what you're referring to, isn't it? You're asking about something closer to the following: ------------------------------------- >>> import java >>> from org.python.core import Py >>> e = java.lang.OutOfMemoryError() >>> try: ... Py.MemoryError(e) ... except: ... import sys ... x = sys.exc_info() ... Out of Memory You might want to try the -mx flag to increase heap size ------------------------------------- Yes, that makes for a problem trying to catch the OutOfMemoryError. I think the difference between an error and an exception helps here. An Error is tough (likely impossible) to recover from, and javadocs even say an error "indicates serious problems that a reasonable application should not try to catch." -rb |