Modify flora license version.
[platform/core/messaging/msg-service.git] / include / utils / MsgException.h
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://floralicense.org/license/
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef MSG_EXCEPTION_H
18 #define MSG_EXCEPTION_H
19
20 /*==================================================================================================
21                                          INCLUDE FILES
22 ==================================================================================================*/
23 #include <stdexcept>
24 #include <string>
25
26 using namespace std;
27
28
29 /*==================================================================================================
30                                          DEFINES
31 ==================================================================================================*/
32 #define THROW(errCode, debugFmt,...) \
33 do {\
34         char __debugBuf[256];\
35         snprintf(__debugBuf, 256, debugFmt, ##__VA_ARGS__);\
36         MsgException e(errCode, __debugBuf);\
37         MSG_FATAL("%s [%d]", e.what(), e.errorCode());\
38     throw e; \
39 } while(0)
40
41
42 /*==================================================================================================
43                                      CLASS DEFINITIONS
44 ==================================================================================================*/
45 class MsgException : public runtime_error //public exception
46 {
47 public:
48         MsgException(int errCode, const string& msg = "")
49             : runtime_error( errorStrings[errCode] + " : " +  msg), eCode(errCode)
50         {}
51
52         enum
53         {
54                 SUCCESS = 0,
55
56                 INVALID_PARAM,
57                 INVALID_RESULT,
58                 SELECT_ERROR,
59                 IPC_ERROR,
60                 OUT_OF_RANGE = 5,
61
62                 SMS_PLG_ERROR,
63                 MMS_PLG_ERROR,
64                 PLUGIN_ERROR,
65                 SENT_STATUS_ERROR,
66                 INCOMING_MSG_ERROR = 10,
67
68                 FILE_ERROR,
69                 SECURITY_ERROR,
70                 SERVER_READY_ERROR = 13,
71
72                 // dont erase NUM_ERRORS. place a new error code in ahead of NUM_ERRORS
73                 NUM_ERRORS
74         };
75
76         int errorCode() { return eCode; }
77
78 private:
79         static string errorStrings[NUM_ERRORS];
80         int eCode;
81 };
82
83 #endif //#ifndef __MSG_EXCEPTION_H__
84
85