From: Peter J. <pj...@wa...> - 2004-02-29 14:44:54
|
Hi David, All, David Jencks <da...@co...> wrote: [...] > I also wonder if the following java code can be translated to C++: > > public static void handleThrowable(Throwable t) throws A, B, C { > try { > throw t; > } catch (FirebirdException fe) { > throw new A(fe); > } catch (OtherException oe) { > throw new B(oe); > } catch (Throwable t2 { > throw new C(t2); > } > } If I don't confuse matters, that's the solution I wanted to offer at seeing Nickolays code. But before pressing "Send" I did compile a test program, and the result was, that the dispatch will again occur based on static static type of t, so that always the last alternative is executed. For the same reason (the information is only in the dynamic type), no template based solution is in sight. It seems to be a situation which can only be handled by virtual member functions or RTTI. In fact, RTTI is essentially a special virtual function call, which is easy to see in Stroustrup's initial implementation (still in Cfront, if I remember right). The typeinfo is pointed to by the zeroth element of the vtable, which was reserved for this very reason since ancient times. In fact OpenWatcom, the compiler I'm bound still to use for obscure reasons, does handle it just the same way. Regards, Peter Jacobi |