Menu

[r20]: / trunk / exception.cpp  Maximize  Restore  History

Download this file

179 lines (144 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* ====================================================================
* Copyright (c) 2002-2005 The RapidSvn Group. All rights reserved.
*
* This software is licensed as described in the file LICENSE.txt,
* which you should have received as part of this distribution.
*
* This software consists of voluntary contributions made by many
* individuals. For exact contribution history, see the revision
* history and logs, available at http://rapidsvn.tigris.org/.
* ====================================================================
*/
// stl
#include <string>
#include <vector>
#include <sstream>
#include <iterator>
#include <algorithm>
// subcpp
#include "exception.hpp"
// svn
#include "svn_wc.h"
namespace svn
{
struct Exception::Data
{
public:
std::string message;
apr_status_t apr_err;
Data( const char * msg )
: message( msg )
{
}
Data( const Data& other )
: message( other.message ), apr_err( other.apr_err )
{
}
};
Exception::Exception( const char * message ) throw()
{
m = new Data( message );
}
Exception::Exception( const Exception & other ) throw()
{
m = new Data( *other.m );
}
Exception::~Exception() throw()
{
delete m;
}
apr_status_t Exception::apr_err() const
{
return m->apr_err;
}
const char * Exception::Message() const
{
return m->message.c_str();
}
const char* Exception::what() const throw()
{
try
{
return Message();
}
catch( ... )
{
return "Encountered a new exception while creating this exception's message.";
}
}
ClientException::ClientException( svn_error_t * error ) throw()
: Exception( "" )
{
if ( error == 0 )
return;
Update( error );
svn_error_clear( error );
}
ClientException::ClientException( apr_status_t status ) throw()
: Exception( "" )
{
m->apr_err = status;
}
ClientException::~ClientException() throw()
{
}
ClientException::ClientException( const ClientException & src ) throw()
: Exception( src.Message() )
{
}
void ClientException::Update( svn_error_t * error )
{
if ( error == 0 )
return;
static const apr_size_t errMessageBufferSize = 500;
std::vector< char > errMessageOutBuffer( errMessageBufferSize, '\0' ); // 300 character error message seems enough?
m->apr_err = error->apr_err;
svn_error_t * next = error->child;
std::string & message = m->message;
std::vector< std::string > messages;
messages.push_back( svn_err_best_message( error, &errMessageOutBuffer[0], errMessageBufferSize ) );
while ( next != 0 )
{
messages.push_back( svn_err_best_message( next, &errMessageOutBuffer[0], errMessageBufferSize ) );
next = next->child;
}
// erase duplicates
messages.erase( std::unique( messages.begin(), messages.end() ), messages.end() );
// combine messagse
std::ostringstream combinedMessage;
std::copy( messages.begin(), messages.end(), std::ostream_iterator< std::string >( combinedMessage, "\n" ) );
// save combination
message = combinedMessage.str();
}
NotifyException::NotifyException() throw() : ClientException( 0 )
{
}
NotifyException::~NotifyException() throw()
{
}
NotifyException::NotifyException( const NotifyException& other ) : ClientException( other )
{
std::vector< const svn_wc_notify_t* >::const_iterator end = other.m_notifications.end();
for ( std::vector< const svn_wc_notify_t* >::const_iterator notification = other.m_notifications.begin(); notification != end; ++notification )
{
AddNotification( *notification );
}
};
void NotifyException::AddNotification( const svn_wc_notify_t* notification )
{
if( m_notifications.empty() )
{
Update( notification->err );
}
m_notifications.push_back( svn_wc_dup_notify( notification, m_pool.pool() ) );
}
ErrorChecker& operator << ( ErrorChecker& checker, svn_error_t* error )
{
if( NULL != error )
{
throw ClientException( error );
}
return( checker );
}
}
MongoDB Logo MongoDB