Return-Path: Delivered-To: apmail-stdcxx-commits-archive@www.apache.org Received: (qmail 15323 invoked from network); 7 May 2008 21:24:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 May 2008 21:24:49 -0000 Received: (qmail 28827 invoked by uid 500); 7 May 2008 21:24:51 -0000 Delivered-To: apmail-stdcxx-commits-archive@stdcxx.apache.org Received: (qmail 28810 invoked by uid 500); 7 May 2008 21:24:51 -0000 Mailing-List: contact commits-help@stdcxx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stdcxx.apache.org Delivered-To: mailing list commits@stdcxx.apache.org Received: (qmail 28792 invoked by uid 99); 7 May 2008 21:24:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2008 14:24:51 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2008 21:24:04 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EF79E2388A2F; Wed, 7 May 2008 14:24:24 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r654286 - in /stdcxx/branches/4.2.x/examples/manual: failure.cpp in/failure.in out/failure.out Date: Wed, 07 May 2008 21:24:24 -0000 To: commits@stdcxx.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080507212424.EF79E2388A2F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebor Date: Wed May 7 14:24:23 2008 New Revision: 654286 URL: http://svn.apache.org/viewvc?rev=654286&view=rev Log: 2008-05-07 Martin Sebor * examples/manual/failure.cpp (main): Demonstrated the (optional) extensions, classes std::ios::badbit_set, std::ios::eofbit_set, and std::ios::failbit_set. * examples/manual/in/failure.in: Added "interesting" input file. * examples/manual/in/failure.in: Set expected output. Added: stdcxx/branches/4.2.x/examples/manual/in/failure.in (with props) Modified: stdcxx/branches/4.2.x/examples/manual/failure.cpp stdcxx/branches/4.2.x/examples/manual/out/failure.out Modified: stdcxx/branches/4.2.x/examples/manual/failure.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/examples/manual/failure.cpp?rev=654286&r1=654285&r2=654286&view=diff ============================================================================== --- stdcxx/branches/4.2.x/examples/manual/failure.cpp (original) +++ stdcxx/branches/4.2.x/examples/manual/failure.cpp Wed May 7 14:24:23 2008 @@ -1,6 +1,7 @@ /************************************************************************** * - * failure.cpp - Example program demonstrating ios::failure. + * failure.cpp - Example program demonstrating the use of ios::failure + * and its extendsions provided by this implementation. * * $Id$ * @@ -22,7 +23,7 @@ * implied. See the License for the specific language governing * permissions and limitations under the License. * - * Copyright 1994-2006 Rogue Wave Software. + * Copyright 1994-2008 Rogue Wave Software, Inc. * **************************************************************************/ @@ -31,39 +32,78 @@ #include + #ifndef _RWSTD_NO_EXCEPTIONS int main () { - try { - // Enable exceptions in cin. - std::cin.exceptions (std::ios::eofbit); - - // Clear all bits and set eofbit. - std::cin.clear (std::ios::eofbit); - } - catch (const std::ios::failure &e) { - std::cout << "Caught an exception: " << e.what () << std::endl; - } - catch (const std::exception &e) { - std::cout << "Caught an exception: " << e.what () << std::endl; - - return 1; // Indicate failure. - } - catch (...) { - std::cout << "Caught an unknown exception" << std::endl; - - return 1; // Indicate failure. - } + const std::ios::iostate allbits = + std::ios::badbit | std::ios::eofbit | std::ios::failbit; + + // Enable all exceptions in cin. + std::cin.exceptions (allbits); + + while (!std::cin.eof ()) { + + // Clear state bits. + std::cin.clear (); + + try { + short i; + char ch; + + // Try to extract a character and an integer. + std::cin >> ch >> i; + + std::cout << ch << ' ' << i << '\n'; + } + +#ifndef _RWSTD_NO_EXT_FAILURE + + // Classes badbit_set, eofbit_set, and failbit_set are + // derived from failure and are optional extensions of + // this implementation. + + catch (const std::ios::badbit_set &e) { + std::cout << "Caught std::ios::badbit_set: " + << e.what () << '\n'; + } + catch (const std::ios::eofbit_set &e) { + std::cout << "Caught std::ios::eofbit_set: " + << e.what () << '\n'; + } + catch (const std::ios::failbit_set &e) { + std::cout << "Caught std::ios::failbit_set: " + << e.what () << '\n'; + } + +#endif // _RWSTD_NO_EXT_FAILURE + + catch (const std::ios::failure &e) { + std::cout << "Caught std::ios::failure: " + << e.what () << '\n'; + } + catch (const std::exception &e) { + std::cout << "Caught std::exception: " + << e.what () << '\n'; + + return 1; // Indicate error. + } + catch (...) { + std::cout << "Caught an unknown exception\n"; + + return 1; // Indicate error. + } + } - return 0; + return 0; } -#else +#else // if defined (_RWSTD_NO_EXCEPTIONS) int main () { - std::cout << "Exceptions not supported." << std::endl; + std::cout << "Exceptions not supported\n"; return 0; } Added: stdcxx/branches/4.2.x/examples/manual/in/failure.in URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/examples/manual/in/failure.in?rev=654286&view=auto ============================================================================== --- stdcxx/branches/4.2.x/examples/manual/in/failure.in (added) +++ stdcxx/branches/4.2.x/examples/manual/in/failure.in Wed May 7 14:24:23 2008 @@ -0,0 +1,4 @@ +a+1234 +b-1234567890 +c+2345 +d- Propchange: stdcxx/branches/4.2.x/examples/manual/in/failure.in ------------------------------------------------------------------------------ svn:eol-style = native Modified: stdcxx/branches/4.2.x/examples/manual/out/failure.out URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/examples/manual/out/failure.out?rev=654286&r1=654285&r2=654286&view=diff ============================================================================== --- stdcxx/branches/4.2.x/examples/manual/out/failure.out (original) +++ stdcxx/branches/4.2.x/examples/manual/out/failure.out Wed May 7 14:24:23 2008 @@ -1 +1,5 @@ -Caught an exception: std::cin: stream object has set ios::eofbit +a 1234 +Caught std::ios::failbit_set: std::cin: stream object has set ios::failbit +c 2345 +Caught std::ios::failbit_set: std::cin: stream object has set ios::failbit +Caught std::ios::failure: std::cin: stream object has set failbit, eofbit