REC RPC library
rec_rpc_Exception.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2011, REC Robotics Equipment Corporation GmbH, Planegg, Germany
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 - Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 - Neither the name of the REC Robotics Equipment Corporation GmbH nor the names of
14  its contributors may be used to endorse or promote products derived from this software
15  without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
18 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
24 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 #ifndef _REC_RPC_EXCEPTION_H_
28 #define _REC_RPC_EXCEPTION_H_
29 
30 #include "rec/rpc/defines.h"
31 
32 #include <QCoreApplication>
33 #include <QString>
34 #include <QMetaType>
35 #include <exception>
36 
37 namespace rec
38 {
39  namespace rpc
40  {
42  enum ErrorCode
43  {
44  NoError = 0,
60  HTTPNotFount = 100,
66  User = 200,
67  };
68 
70  class REC_RPC_EXPORT Exception : public std::exception
71  {
72  Q_DECLARE_TR_FUNCTIONS( rec::rpc::Exception );
73 
74  public:
80  Exception( ErrorCode code = UnknownError, const QString& detail = QString::null );
82  virtual ~Exception() throw();
83 
85  ErrorCode errorCode() const;
87  QString getMessage() const;
89  QString detail() const;
90 
96  virtual const char* what() const throw();
97 
105  static QString messageFromErrorCode( ErrorCode code );
106 
107  private:
108  ErrorCode _code;
109  mutable QByteArray _msg;
110  const QString _detail;
111  };
112  }
113 }
114 
115 Q_DECLARE_METATYPE( rec::rpc::ErrorCode );
116 
117 #endif //_REC_RPC_EXCEPTION_H_
ErrorCode
Pre-defined error codes.
Exception class.
#define REC_RPC_EXPORT
Definition: defines.h:49