Am Mittwoch, 6. Oktober 2004 18:12 schrieb Curt Arnold:
> > Defering is good, but I would derive Exception from runtime_error,
> > which needs
> > a std::string in constructor, so the conversion need to be done in the
> > constructor.
> >
> > Another possible solution is to use runtime_error, give the
> > constructor a
> > empty string and override what().
>
> I'd suggest doing in the constructor at least for now. I might be able
> to tweak it when doing the Unicode rework if it appears to be a
> significant performance issue.
Ok, here is the patch against current CVS.
The string is converted in the constructor. In case String is defined as
std::string, there is no conversion done at all.
I tested it with g++-3.3.3.
Tommi
? config.log
? config.status
? exception.diff
? include/log4cxx/config_auto.h
? include/log4cxx/config_auto.h.in
? include/log4cxx/config_msvc.h
? include/log4cxx/stamp-h1
Index: include/log4cxx/helpers/condition.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/condition.h,v
retrieving revision 1.7
diff -r1.7 condition.h
34a35,37
> public:
> ConditionException(const String& message = "ConditionException")
> : Exception(message) {}
Index: include/log4cxx/helpers/exception.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/exception.h,v
retrieving revision 1.10
diff -r1.10 exception.h
20a21
> #include <stdexcept>
29c30
< class LOG4CXX_EXPORT Exception
---
> class LOG4CXX_EXPORT Exception : public std::runtime_error
30a32,40
> template <typename string_type>
> static std::string narrow(const string_type& s)
> { return std::string(s.begin(), s.end()); }
>
> // specialize for std::string
> static std::string narrow(const std::string& s)
> { return s; }
>
> String message;
32,33c42,45
< Exception() {}
< Exception(const String& message): message(message) {}
---
> Exception(const String& message)
> : std::runtime_error(narrow(message)),
> message(message) {}
> ~Exception() throw () {}
36,38d47
< protected:
< String message;
<
47d55
< RuntimeException() {}
58d65
< NullPointerException() {}
77a85,87
> public:
> IOException(const String& message = "IOException")
> : Exception(message) { }
Index: include/log4cxx/helpers/inetaddress.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/inetaddress.h,v
retrieving revision 1.8
diff -r1.8 inetaddress.h
29a30,32
> public:
> UnknownHostException(const String& message = "UnknownHostException")
> : Exception(message) {}
Index: include/log4cxx/helpers/mutex.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/mutex.h,v
retrieving revision 1.7
diff -r1.7 mutex.h
32a33,35
> public:
> MutexException(const String& message = "MutexException")
> : Exception(message) { }
Index: include/log4cxx/helpers/resourcebundle.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/resourcebundle.h,v
retrieving revision 1.4
diff -r1.4 resourcebundle.h
30a31,33
> public:
> MissingResourceException(const String& message = "MissingResourceException")
> : Exception(message) {}
Index: include/log4cxx/helpers/semaphore.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/semaphore.h,v
retrieving revision 1.11
diff -r1.11 semaphore.h
32a33,35
> public:
> SemaphoreException(const String& message = "SemaphoreException")
> : Exception(message) {}
Index: include/log4cxx/helpers/socketimpl.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/socketimpl.h,v
retrieving revision 1.11
diff -r1.11 socketimpl.h
33a34
> static String getSocketErrorMessage();
35c36,39
< SocketException();
---
> SocketException()
> : IOException(getSocketErrorMessage()) {}
> SocketException(const String& message)
> : IOException(message) {}
43a48,51
> public:
> ConnectException(const String& message)
> : SocketException(message) {}
> ConnectException() {}
51a60,63
> public:
> BindException(const String& message)
> : SocketException(message) {}
> BindException() {}
61a74,77
> public:
> InterruptedIOException(const String& message)
> : IOException(message) {}
> InterruptedIOException() {}
67a84,87
> public:
> SocketTimeoutException(const String& message)
> : InterruptedIOException(message) {}
> SocketTimeoutException() {}
Index: include/log4cxx/helpers/socketinputstream.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/socketinputstream.h,v
retrieving revision 1.10
diff -r1.10 socketinputstream.h
36a37,39
> public:
> EOFException(const String& message = "EOFException")
> : Exception(message) {}
Index: include/log4cxx/helpers/stringtokenizer.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/stringtokenizer.h,v
retrieving revision 1.6
diff -r1.6 stringtokenizer.h
28a29,31
> public:
> NoSuchElementException(const String& message = "NoSuchElementException")
> : Exception(message) {}
Index: include/log4cxx/helpers/thread.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/thread.h,v
retrieving revision 1.15
diff -r1.15 thread.h
44a45,47
> public:
> ThreadException(const String& message = "ThreadException")
> : Exception(message) {}
48a52,54
> public:
> InterruptedException(const String& message = "InterruptedException ")
> : Exception(message) {}
Index: include/log4cxx/helpers/xml.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/xml.h,v
retrieving revision 1.7
diff -r1.7 xml.h
42a43,45
> public:
> DOMException(const String& message = "DOMException")
> : RuntimeException(message) {}
Index: include/log4cxx/spi/appenderattachable.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/spi/appenderattachable.h,v
retrieving revision 1.9
diff -r1.9 appenderattachable.h
21d20
< #include <vector>
28,32d26
< // Forward Declarations
< class Appender;
< typedef helpers::ObjectPtrT<Appender> AppenderPtr;
< typedef std::vector<AppenderPtr> AppenderList;
<
Index: src/class.cpp
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/src/class.cpp,v
retrieving revision 1.9
diff -r1.9 class.cpp
40a41
> : Exception(_T("Class '") + className + _T("' not found"))
42d42
< message = _T("Class '") + className + _T("' not found");
Index: src/fileappender.cpp
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/src/fileappender.cpp,v
retrieving revision 1.10
diff -r1.10 fileappender.cpp
98c98
< throw RuntimeException();
---
> throw RuntimeException("open file");
Index: src/socketimpl.cpp
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/src/socketimpl.cpp,v
retrieving revision 1.15
diff -r1.15 socketimpl.cpp
62c62
< SocketException::SocketException()
---
> String SocketException::getSocketErrorMessage()
91c91
< message = messageBuffer;
---
> return messageBuffer;
96c96
< message = A2T(strerror(errno));
---
> return A2T(strerror(errno));