update tizen source
[framework/messaging/msg-service.git] / include / utils / MsgException.h
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #ifndef MSG_EXCEPTION_H
32 #define MSG_EXCEPTION_H
33
34 /*==================================================================================================
35                                          INCLUDE FILES
36 ==================================================================================================*/
37 #include <stdexcept>
38 #include <string>
39
40 using namespace std;
41
42
43 /*==================================================================================================
44                                          DEFINES
45 ==================================================================================================*/
46 #define THROW(errCode, debugFmt,...) \
47 do {\
48         char __debugBuf[256];\
49         snprintf(__debugBuf, 256, debugFmt, ##__VA_ARGS__);\
50         MsgException e(errCode, __debugBuf);\
51         MSG_FATAL("%s [%d]", e.what(), e.errorCode());\
52     throw e; \
53 } while(0)
54
55
56 /*==================================================================================================
57                                      CLASS DEFINITIONS
58 ==================================================================================================*/
59 class MsgException : public runtime_error //public exception
60 {
61 public:
62         MsgException(int errCode, const string& msg = "")
63             : runtime_error( errorStrings[errCode] + " : " +  msg), eCode(errCode)
64         {}
65
66         enum
67         {
68                 SUCCESS = 0,
69
70                 INVALID_PARAM,
71                 INVALID_RESULT,
72                 SELECT_ERROR,
73                 IPC_ERROR,
74                 OUT_OF_RANGE = 5,
75
76                 SMS_PLG_ERROR,
77                 MMS_PLG_ERROR,
78                 PLUGIN_ERROR,
79                 SENT_STATUS_ERROR,
80                 INCOMING_MSG_ERROR = 10,
81
82                 FILE_ERROR,
83                 SECURITY_ERROR,
84                 SERVER_READY_ERROR = 13,
85
86                 // dont erase NUM_ERRORS. place a new error code in ahead of NUM_ERRORS
87                 NUM_ERRORS
88         };
89
90         int errorCode() { return eCode; }
91
92 private:
93         static string errorStrings[NUM_ERRORS];
94         int eCode;
95 };
96
97 #endif //#ifndef __MSG_EXCEPTION_H__
98
99