Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53190 - sandbox/memory/libs/memory/examples/exception_semantics
From: xushiweizh_at_[hidden]
Date: 2009-05-22 17:31:52


Author: xushiwei
Date: 2009-05-22 17:31:50 EDT (Fri, 22 May 2009)
New Revision: 53190
URL: http://svn.boost.org/trac/boost/changeset/53190

Log:
exception semantics
Added:
   sandbox/memory/libs/memory/examples/exception_semantics/
   sandbox/memory/libs/memory/examples/exception_semantics/exception_semantics.cpp (contents, props changed)

Added: sandbox/memory/libs/memory/examples/exception_semantics/exception_semantics.cpp
==============================================================================
--- (empty file)
+++ sandbox/memory/libs/memory/examples/exception_semantics/exception_semantics.cpp 2009-05-22 17:31:50 EDT (Fri, 22 May 2009)
@@ -0,0 +1,77 @@
+//
+// exception_semantics.cpp
+//
+// Copyright (c) 2004 - 2008 xushiwei (xushiweizh_at_[hidden])
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/memory/index.htm for documentation.
+//
+#include <cstdio>
+#include <boost/memory.hpp>
+
+class A
+{
+public:
+ A() {}
+ void init() {
+ printf("A::A\n");
+ }
+ ~A() {
+ printf("A::~A\n");
+ }
+};
+
+class B
+{
+public:
+ B() {}
+ void init() {
+ printf("B::B\n");
+ }
+ ~B() {
+ printf("B::~B\n");
+ }
+};
+
+class Foo
+{
+private:
+ A m_a;
+ B m_b;
+
+public:
+ Foo() {
+ m_a.init();
+ throw 1;
+ m_b.init();
+ }
+ ~Foo() {
+ printf("Foo::~Foo\n");
+ }
+};
+
+void testExceptionSemantics()
+{
+ try
+ {
+ Foo* p = new Foo;
+ }
+ catch (...)
+ {
+ printf("Unexcepted\n");
+ }
+
+ printf("Now, let's test operator new of GC Allocator...\n");
+ try
+ {
+ boost::auto_alloc alloc;
+ Foo* p = BOOST_NEW(alloc, Foo);
+ }
+ catch (...)
+ {
+ printf("Unexcepted\n");
+ }
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk