|
From: <bc...@wo...> - 2001-03-15 08:32:42
|
[Richard Gruet]
>Hi,
>
>If I define a Java 2 exceptions classes with one being a subclass of the
>other:
>
>public class BaseException extends Exception
>{ ... }
>
>public class DerivedException extends BaseException
>{ ... }
>
>And if the DerivedException is raised in a Java program, I can catch it
>in Jython as a DerivedException but *not* as a BaseException, i.e the
>following code:
>
>try:
> # call the java prog that raises a DerivedException
>except DerivedException, e:
> print "Got a DerivedException :", e
>
>... will display "Got a DerivedException : ...." (which is OK)
>
>whereas the code:
>
>try:
> # call the java prog that raises a DerivedException
>except BaseException, e:
> print "Got a BaseException :", e
>else:
> import sys
> exc_type, exc_value, exc_traceback = sys.exc_info()
> print 'uncaught exception', exc_type, exc_value, exc_traceback
>
>...will display "uncaught exception ..." instead of "Got a
>BaseException..."
>
>This looks abnormal to me!
>Am I missing something or is it a bug ? Thanks for any clue.
The code belows works for me. Could you create a small standalone
example of the problem?
regards,
finn
------------ BaseException.java ------------
public class BaseException extends Exception { }
------------ DerivedException.java ------------
public class DerivedException extends BaseException { }
------------ j.java ------------
public class j {
public static void foo() throws BaseException {
throw new BaseException();
}
public static void bar() throws BaseException {
throw new DerivedException();
}
public static void baz() throws DerivedException {
throw new DerivedException();
}
}
------------ tst.py ------------
import j, BaseException, DerivedException
try:
raise DerivedException()
except DerivedException, e:
print "Got a DerivedException :", e
try:
raise DerivedException()
except BaseException, e:
print "Got a BaseException :", e
else:
import sys
exc_type, exc_value, exc_traceback = sys.exc_info()
print 'uncaught exception', exc_type, exc_value, exc_traceback
try:
j.bar()
except DerivedException, e:
print "Got a DerivedException :", e
try:
j.bar()
except BaseException, e:
print "Got a BaseException :", e
try:
j.foo()
except BaseException, e:
print "Got a BaseException :", e
else:
import sys
exc_type, exc_value, exc_traceback = sys.exc_info()
print 'uncaught exception', exc_type, exc_value, exc_traceback
try:
j.baz()
except BaseException, e:
print "Got a BaseException :", e
|