2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef MSG_EXCEPTION_H
18 #define MSG_EXCEPTION_H
20 /*==================================================================================================
22 ==================================================================================================*/
29 /*==================================================================================================
31 ==================================================================================================*/
32 #define THROW(errCode, debugFmt, ...) \
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());\
42 /*==================================================================================================
44 ==================================================================================================*/
45 class MsgException : public runtime_error /* public exception */
48 MsgException(int errCode, const string& msg = "")
49 : runtime_error(errorStrings[errCode] + " : " + msg), eCode(errCode) {
66 INCOMING_MSG_ERROR = 10,
70 SERVER_READY_ERROR = 13,
73 /* dont erase NUM_ERRORS. place a new error code in ahead of NUM_ERRORS */
77 int errorCode() { return eCode; }
80 static string errorStrings[NUM_ERRORS];
84 #endif /* __MSG_EXCEPTION_H__ */