diff options
Diffstat (limited to 'ACE/contrib/utility/Documentation/ExH/Example/compound.cpp.html')
-rw-r--r-- | ACE/contrib/utility/Documentation/ExH/Example/compound.cpp.html | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/ACE/contrib/utility/Documentation/ExH/Example/compound.cpp.html b/ACE/contrib/utility/Documentation/ExH/Example/compound.cpp.html new file mode 100644 index 00000000000..40ecf71eee9 --- /dev/null +++ b/ACE/contrib/utility/Documentation/ExH/Example/compound.cpp.html @@ -0,0 +1,153 @@ +<html> +<head> +<!-- Generated by the Spirit (http://spirit.sf.net) C++ to HTML Converter --> +<title> +compound.cpp</title> +<link rel="stylesheet" href="../../../Documentation/Style/CXX.css" type="text/css"></head> +<body> +<pre> +<span class=comment>// file : Example/ExH/Compound/compound.cpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +</span><span class=preprocessor>#include "Utility/ExH/Compound.hpp" +</span><span class=preprocessor>#include "Utility/ExH/System/Exception.hpp" +</span><span class=preprocessor>#include "Utility/ExH/Logic/DescriptiveException.hpp" + +</span><span class=comment>// Include some helper converters to allow exception initialization +// with std::ostringstream + +</span><span class=preprocessor>#include "Utility/ExH/StringStreamConverter.hpp" + +</span><span class=preprocessor>#include <iostream> + +</span><span class=keyword>using </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>cerr</span><span class=special>; +</span><span class=keyword>using </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>endl</span><span class=special>; +</span><span class=keyword>using </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>; +</span><span class=keyword>using </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>ostringstream</span><span class=special>; + +</span><span class=keyword>using </span><span class=keyword>namespace </span><span class=identifier>Utility</span><span class=special>::</span><span class=identifier>ExH</span><span class=special>; + +</span><span class=comment>// Here are our components + +</span><span class=keyword>class </span><span class=identifier>Base +</span><span class=special>{ +</span><span class=keyword>public</span><span class=special>: + + </span><span class=comment>// + // Exception definitions. + // + + // Base logic exception class for component. + </span><span class=keyword>class </span><span class=identifier>Exception_ </span><span class=special>{}; + </span><span class=keyword>typedef + </span><span class=identifier>Compound </span><span class=special><</span><span class=identifier>Exception_</span><span class=special>, </span><span class=identifier>Logic</span><span class=special>::</span><span class=identifier>DescriptiveException</span><span class=special>> + </span><span class=identifier>Exception</span><span class=special>; + + </span><span class=keyword>class </span><span class=identifier>InvalidArgument_ </span><span class=special>{}; + </span><span class=keyword>typedef + </span><span class=identifier>Compound </span><span class=special><</span><span class=identifier>InvalidArgument_</span><span class=special>, </span><span class=identifier>Exception</span><span class=special>> + </span><span class=identifier>InvalidArgument</span><span class=special>; + + </span><span class=keyword>class </span><span class=identifier>NotInitialized_ </span><span class=special>{}; + </span><span class=keyword>typedef + </span><span class=identifier>Compound </span><span class=special><</span><span class=identifier>NotInitialized_</span><span class=special>, </span><span class=identifier>Exception</span><span class=special>> + </span><span class=identifier>NotInitialized</span><span class=special>; + +</span><span class=keyword>public</span><span class=special>: + + </span><span class=keyword>void + </span><span class=identifier>foo </span><span class=special>(</span><span class=keyword>char </span><span class=keyword>const</span><span class=special>* </span><span class=identifier>str</span><span class=special>) </span><span class=keyword>throw </span><span class=special>(</span><span class=identifier>InvalidArgument</span><span class=special>, </span><span class=identifier>NotInitialized</span><span class=special>) + </span><span class=special>{ + </span><span class=comment>// This is just an example. + + </span><span class=keyword>if </span><span class=special>(</span><span class=identifier>str </span><span class=special>== </span><span class=number>0</span><span class=special>) + </span><span class=special>{ + </span><span class=keyword>throw </span><span class=identifier>InvalidArgument </span><span class=special>(</span><span class=string>"Base::foo: first parameter is zero."</span><span class=special>); + </span><span class=special>} + </span><span class=keyword>else + </span><span class=special>{ + </span><span class=identifier>ostringstream </span><span class=identifier>ostr</span><span class=special>; + </span><span class=identifier>ostr </span><span class=special><< </span><span class=string>"Base::foo [this = " </span><span class=special><< </span><span class=keyword>this </span><span class=special><< </span><span class=string>"]: object is not initialized."</span><span class=special>; + + </span><span class=keyword>throw </span><span class=identifier>NotInitialized </span><span class=special>(</span><span class=identifier>ostr</span><span class=special>); + </span><span class=special>} + </span><span class=special>} + + + </span><span class=comment>// We don't know what implementation may decide to throw so + // we allow to throw System exception and any logic exception + // derived from Base::Exception + </span><span class=keyword>virtual </span><span class=keyword>void + </span><span class=identifier>vfoo </span><span class=special>() </span><span class=keyword>throw </span><span class=special>(</span><span class=identifier>Exception</span><span class=special>, </span><span class=identifier>System</span><span class=special>::</span><span class=identifier>Exception</span><span class=special>) </span><span class=special>= </span><span class=number>0</span><span class=special>; +</span><span class=special>}; + +</span><span class=keyword>class </span><span class=identifier>Derived </span><span class=special>: </span><span class=keyword>public </span><span class=identifier>Base +</span><span class=special>{ +</span><span class=keyword>public</span><span class=special>: + + </span><span class=comment>// Define some Derived-specific logic exception. + </span><span class=keyword>class </span><span class=identifier>NotImplemented_ </span><span class=special>{}; + </span><span class=keyword>typedef + </span><span class=identifier>Compound </span><span class=special><</span><span class=identifier>NotImplemented_</span><span class=special>, </span><span class=identifier>Exception</span><span class=special>> + </span><span class=identifier>NotImplemented</span><span class=special>; + +</span><span class=keyword>public</span><span class=special>: + </span><span class=keyword>virtual </span><span class=keyword>void + </span><span class=identifier>vfoo </span><span class=special>() </span><span class=keyword>throw </span><span class=special>(</span><span class=identifier>NotImplemented</span><span class=special>, </span><span class=identifier>System</span><span class=special>::</span><span class=identifier>Exception</span><span class=special>) + </span><span class=special>{ + </span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string </span><span class=identifier>str </span><span class=special>(</span><span class=string>"Derived::vfoo: not implemented yet."</span><span class=special>); + </span><span class=keyword>throw </span><span class=identifier>NotImplemented </span><span class=special>(</span><span class=identifier>str</span><span class=special>); + </span><span class=special>} +</span><span class=special>}; + +</span><span class=keyword>int +</span><span class=identifier>main </span><span class=special>() +</span><span class=special>{ + </span><span class=keyword>try + </span><span class=special>{ + + </span><span class=identifier>Derived </span><span class=identifier>d</span><span class=special>; + </span><span class=identifier>Base</span><span class=special>* </span><span class=identifier>pb </span><span class=special>(&</span><span class=identifier>d</span><span class=special>); + + </span><span class=comment>// We can use generic handler. + </span><span class=keyword>try + </span><span class=special>{ + </span><span class=identifier>pb</span><span class=special>-></span><span class=identifier>vfoo </span><span class=special>(); + </span><span class=special>} + </span><span class=keyword>catch </span><span class=special>(</span><span class=identifier>Base</span><span class=special>::</span><span class=identifier>Exception </span><span class=keyword>const</span><span class=special>& </span><span class=identifier>ex</span><span class=special>) + </span><span class=special>{ + </span><span class=identifier>cerr </span><span class=special><< </span><span class=string>"Caught Base::Exception: " </span><span class=special><< </span><span class=identifier>ex</span><span class=special>.</span><span class=identifier>what </span><span class=special>() </span><span class=special><< </span><span class=identifier>endl</span><span class=special>; + </span><span class=special>} + + + </span><span class=comment>// Or use more precise control. + </span><span class=keyword>try + </span><span class=special>{ + </span><span class=identifier>pb</span><span class=special>-></span><span class=identifier>foo </span><span class=special>(</span><span class=string>"hello"</span><span class=special>); + </span><span class=special>} + </span><span class=keyword>catch </span><span class=special>(</span><span class=identifier>Base</span><span class=special>::</span><span class=identifier>NotInitialized </span><span class=keyword>const</span><span class=special>& </span><span class=identifier>ex</span><span class=special>) + </span><span class=special>{ + </span><span class=identifier>cerr </span><span class=special><< </span><span class=string>"Caught Base::NotInitialized: " </span><span class=special><< </span><span class=identifier>ex</span><span class=special>.</span><span class=identifier>what </span><span class=special>() </span><span class=special><< </span><span class=identifier>endl</span><span class=special>; + </span><span class=special>} + + </span><span class=comment>// Or use application-level handler. + </span><span class=identifier>pb</span><span class=special>-></span><span class=identifier>foo </span><span class=special>(</span><span class=number>0</span><span class=special>); + + </span><span class=special>} + </span><span class=keyword>catch </span><span class=special>(</span><span class=identifier>Logic</span><span class=special>::</span><span class=identifier>Exception </span><span class=keyword>const</span><span class=special>& </span><span class=identifier>ex</span><span class=special>) + </span><span class=special>{ + </span><span class=identifier>cerr </span><span class=special><< </span><span class=string>"Caught Logic::Exception: " </span><span class=special><< </span><span class=identifier>ex</span><span class=special>.</span><span class=identifier>what </span><span class=special>() </span><span class=special><< </span><span class=identifier>endl</span><span class=special>; + </span><span class=special>} + </span><span class=keyword>catch </span><span class=special>(...) + </span><span class=special>{ + </span><span class=identifier>cerr </span><span class=special><< </span><span class=string>"Caught unknown exception using catch-all handler" </span><span class=special><< </span><span class=identifier>endl</span><span class=special>; + </span><span class=keyword>return </span><span class=special>-</span><span class=number>1</span><span class=special>; + </span><span class=special>} + +</span><span class=special>} +</span></pre> +</body> +</html> +<!-- $Id$ --> |