Commit d78e147a by Benjamin Kosnik Committed by Benjamin Kosnik

C++STYLE: Add exception bits.


2003-12-01  Benjamin Kosnik  <bkoz@redhat.com>

	* docs/html/17_intro/C++STYLE: Add exception bits.
	* include/bits/fstream.tcc: Add location info to exception strings.

	* include/bits/stl_construct.h: Formatting tweaks.

From-SVN: r74119
parent aa66a642
2003-12-01 Benjamin Kosnik <bkoz@redhat.com>
* docs/html/17_intro/C++STYLE: Add exception bits.
* include/bits/fstream.tcc: Add location info to exception strings.
* include/bits/stl_construct.h: Formatting tweaks.
2003-12-01 Paolo Carlini <pcarlini@suse.de> 2003-12-01 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/10378 PR libstdc++/10378
......
...@@ -200,7 +200,25 @@ Notable areas of divergence from what may be previous local practice ...@@ -200,7 +200,25 @@ Notable areas of divergence from what may be previous local practice
For more explanation and examples, see src/globals.cc. All such For more explanation and examples, see src/globals.cc. All such
variables should be contained in that file, for simplicity. variables should be contained in that file, for simplicity.
15. Exception abstractions
Use the exception abstractions found in functexcept.h, which allow
C++ programmers to use this library with -fno-exceptions. (Even if
that is rarely advisable, it's a necessary evil for backwards
compatibility.)
16. Exception error messages
All start with the name of the function where the exception is
thrown, and then (optional) descriptive text is added. Example:
__throw_logic_error("basic_string::_S_construct NULL not valid");
Reason: The verbose terminate handler prints out exception::what(),
as well as the typeinfo for the thrown exception. As this is the
default terminate handler, by putting location info into the
exception string, a very useful error message is printed out for
uncaught exceptions. So useful, in fact, that non-programmers can
give useful error messages, and programmers can intelligently
speculate what went wrong without even using a debugger.
The library currently has a mixture of GNU-C and modern C++ coding The library currently has a mixture of GNU-C and modern C++ coding
styles. The GNU C usages will be combed out gradually. styles. The GNU C usages will be combed out gradually.
......
...@@ -254,7 +254,8 @@ namespace std ...@@ -254,7 +254,8 @@ namespace std
// codecvt::max_length() is bogus. // codecvt::max_length() is bogus.
if (_M_ext_end - _M_ext_buf + __rlen > _M_ext_buf_size) if (_M_ext_end - _M_ext_buf + __rlen > _M_ext_buf_size)
{ {
__throw_ios_failure("codecvt::max_length() " __throw_ios_failure("basic_filebuf::underflow "
"codecvt::max_length() "
"is not valid"); "is not valid");
} }
streamsize __elen = _M_file.xsgetn(_M_ext_end, __rlen); streamsize __elen = _M_file.xsgetn(_M_ext_end, __rlen);
...@@ -305,10 +306,12 @@ namespace std ...@@ -305,10 +306,12 @@ namespace std
// However, reaching it while looping on partial means that // However, reaching it while looping on partial means that
// the file has got an incomplete character. // the file has got an incomplete character.
if (__r == codecvt_base::partial) if (__r == codecvt_base::partial)
__throw_ios_failure("incomplete character in file"); __throw_ios_failure("basic_filebuf::underflow "
"incomplete character in file");
} }
else else
__throw_ios_failure("invalid byte sequence in file"); __throw_ios_failure("basic_filebuf::underflow "
"invalid byte sequence in file");
} }
return __ret; return __ret;
} }
......
// nonstandard construct and destroy functions -*- C++ -*- // nonstandard construct and destroy functions -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -72,13 +72,13 @@ namespace std ...@@ -72,13 +72,13 @@ namespace std
* object's constructor with an initializer. * object's constructor with an initializer.
* @endif * @endif
*/ */
template <class _T1, class _T2> template<typename _T1, typename _T2>
inline void inline void
_Construct(_T1* __p, const _T2& __value) _Construct(_T1* __p, const _T2& __value)
{ {
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// 402. wrong new expression in [some_]allocator::construct // 402. wrong new expression in [some_]allocator::construct
::new (static_cast<void*>(__p)) _T1(__value); ::new(static_cast<void*>(__p)) _T1(__value);
} }
/** /**
...@@ -87,13 +87,13 @@ namespace std ...@@ -87,13 +87,13 @@ namespace std
* object's default constructor (no initializers). * object's default constructor (no initializers).
* @endif * @endif
*/ */
template <class _T1> template<typename _T1>
inline void inline void
_Construct(_T1* __p) _Construct(_T1* __p)
{ {
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// 402. wrong new expression in [some_]allocator::construct // 402. wrong new expression in [some_]allocator::construct
::new (static_cast<void*>(__p)) _T1(); ::new(static_cast<void*>(__p)) _T1();
} }
/** /**
...@@ -101,7 +101,7 @@ namespace std ...@@ -101,7 +101,7 @@ namespace std
* Destroy the object pointed to by a pointer type. * Destroy the object pointed to by a pointer type.
* @endif * @endif
*/ */
template <class _Tp> template<typename _Tp>
inline void inline void
_Destroy(_Tp* __pointer) _Destroy(_Tp* __pointer)
{ __pointer->~_Tp(); } { __pointer->~_Tp(); }
...@@ -113,7 +113,7 @@ namespace std ...@@ -113,7 +113,7 @@ namespace std
* This is a helper function used only by _Destroy(). * This is a helper function used only by _Destroy().
* @endif * @endif
*/ */
template <class _ForwardIterator> template<typename _ForwardIterator>
inline void inline void
__destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type) __destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type)
{ for ( ; __first != __last; ++__first) std::_Destroy(&*__first); } { for ( ; __first != __last; ++__first) std::_Destroy(&*__first); }
...@@ -127,7 +127,7 @@ namespace std ...@@ -127,7 +127,7 @@ namespace std
* This is a helper function used only by _Destroy(). * This is a helper function used only by _Destroy().
* @endif * @endif
*/ */
template <class _ForwardIterator> template<typename _ForwardIterator>
inline void inline void
__destroy_aux(_ForwardIterator, _ForwardIterator, __true_type) __destroy_aux(_ForwardIterator, _ForwardIterator, __true_type)
{ } { }
...@@ -139,7 +139,7 @@ namespace std ...@@ -139,7 +139,7 @@ namespace std
* away, otherwise the objects' destructors must be invoked. * away, otherwise the objects' destructors must be invoked.
* @endif * @endif
*/ */
template <class _ForwardIterator> template<typename _ForwardIterator>
inline void inline void
_Destroy(_ForwardIterator __first, _ForwardIterator __last) _Destroy(_ForwardIterator __first, _ForwardIterator __last)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment