1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 #pragma once
18 #ifndef ZORBA_FATAL_H
19 #define ZORBA_FATAL_H
20 
21 #include <string>
22 
23 #include "util/string_util.h"
24 
25 namespace zorba {
26 
27 /**
28  * Helper function for the ZORBA_FATAL() macro.  This is called only if the
29  * condition fails.  This function calls abort(3).
30  *
31  * @param condition The string representation of the condition that failed.
32  * @param file The C++ source-code file name where the condition failed.
33  * @param line The C++ source-code line number where the condition failed.
34  */
35 void fatal( char const *condition, char const *file, int line,
36             char const *msg );
37 
38 #define ZORBA_FATAL(COND,MSG)                                 \
39   do {                                                        \
40     if ( !(COND) ) {                                          \
41       std::string const msg( BUILD_STRING( MSG ) );           \
42       zorba::fatal( #COND, __FILE__, __LINE__, msg.c_str() ); \
43       throw 0; /* never gets here but suppresses warning */   \
44     }                                                         \
45   } while (0)
46 
47 } // namespace zorba
48 #endif /* ZORBA_FATAL_H */
49 /* vim:set et sw=2 ts=2: */
50