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_ZORBA_EXCEPTION_H
19 #define ZORBA_ZORBA_EXCEPTION_H
20 
21 #include <zorba/zorba_exception.h>
22 
23 namespace zorba {
24 
25 ////////// ZorbaException creation ////////////////////////////////////////////
26 
27 /**
28  * Helper function to clone a ZorbaException in order to keep ZorbaException's
29  * clone() member function \c protected.
30  *
31  * @param e The ZorbaException to clone.
32  * @return Returns a clone of \a e.
33  */
clone(ZorbaException const & e)34 inline std::unique_ptr<ZorbaException> clone( ZorbaException const &e ) {
35   return e.clone();
36 }
37 
38 /**
39  * Makes a ZorbaException.
40  *
41  * @param raise_file The C++ source-code file name whence the exception was
42  * raised.
43  * @param raise_line The C++ source-code line number whence the exception was
44  * raised.
45  * @param diagnostic The diagnostic.
46  * @param params The message parameters.
47  * @return Returns a new ZorbaException.
48  */
49 ZorbaException
50 make_zorba_exception( char const *raise_file,
51                       ZorbaException::line_type raise_line,
52                       Diagnostic const &diagnostic,
53                       internal::diagnostic::parameters const &params =
54                         internal::diagnostic::parameters::empty );
55 
56 /**
57  * Dynamically allocates a Zorbaxception.
58  *
59  * @param raise_file The C++ source-code file name whence the exception was
60  * raised.
61  * @param raise_line The C++ source-code line number whence the exception was
62  * raised.
63  * @param diagnostic The diagnostic.
64  * @param params The message parameters.
65  * @return Returns a new Zorbaxception.
66  */
67 ZorbaException*
68 new_zorba_exception( char const *raise_file,
69                      ZorbaException::line_type raise_line,
70                      Diagnostic const &diagnostic,
71                      internal::diagnostic::parameters const &params =
72                       internal::diagnostic::parameters::empty );
73 
74 /**
75  * The macro to use to create a ZorbaException.
76  * \hideinitializer
77  */
78 #define ZORBA_EXCEPTION(...) \
79   ::zorba::make_zorba_exception( __FILE__, __LINE__, ::zorba:: __VA_ARGS__ )
80 
81 /**
82  * Creates a dynamically allocated Zorbaxception using the local name of an
83  * error.
84  * \hideinitializer
85  */
86 #define NEW_ZORBA_EXCEPTION(...) \
87   ::zorba::new_zorba_exception( __FILE__, __LINE__, ::zorba:: __VA_ARGS__ )
88 
89 /**
90  * Convenience macro for throwing "I/O error" exception.
91  * \hideinitializer
92  */
93 #define ZORBA_IO_EXCEPTION(FUNC,PATH) \
94   ZORBA_EXCEPTION( zerr::ZOSE0004_IO_ERROR, ERROR_PARAMS( PATH, ::zorba::os_error::get_err_string( FUNC ) ) )
95 
96 ///////////////////////////////////////////////////////////////////////////////
97 
98 } // namespace zorba
99 #endif /* ZORBA_ZORBA_EXCEPTION_H */
100 /* vim:set et sw=2 ts=2: */
101