[antlr-interest] "finally" blocks

Paul J. Lucas pauljlucas at mac.com
Mon Jan 17 15:13:55 PST 2005

On Mon, 17 Jan 2005, Christopher Schultz wrote:

> I think that's a flawed comparison. Destructors are in C++ what finalizers
> are in Java.  A "finally" block is different.

	Yes, but I can use destructors in C++ to implement "finally"

		class bool_flag {
		   bool_flag( bool &b ) : m_b( b ) {
		       m_b = true;
		   ~bool_flag() {
		       m_b = false;
		   bool &m_b;

		bool my_flag;

		void f() {
		    bool_flag( my_flag );
		    // ...

	No matter how f() exits, the "finally" of setting my_flag to
	false will always be done.  Hence, destructors can be used to
	implement "finally" (that's why C++ doesn't need "finally"
	explicitly) but Java having "finally" can't get you

	- Paul

More information about the antlr-interest mailing list