BitmapToolkit Scol plugin
exceptions.h
Go to the documentation of this file.
1/**********************************************************
2 Software developed by AVA ( Ava Group of the University of Cordoba, ava at uco dot es)
3 Main author Rafael Munoz Salinas (rmsalinas at uco dot es)
4 This software is released under BSD license as expressed below
5-------------------------------------------------------------------
6Copyright (c) 2013, AVA ( Ava Group University of Cordoba, ava at uco dot es)
7All rights reserved.
8
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
121. Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
142. Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
173. All advertising materials mentioning features or use of this software
18 must display the following acknowledgement:
19
20 This product includes software developed by the Ava group of the University of Cordoba.
21
224. Neither the name of the University nor the names of its contributors
23 may be used to endorse or promote products derived from this software
24 without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY AVA ''AS IS'' AND ANY
27EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29DISCLAIMED. IN NO EVENT SHALL AVA BE LIABLE FOR ANY
30DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36****************************************************************/
37
38#ifndef _RaspiCam__Exceptions_h
39#define _RaspiCam__Exceptions_h
40#include <string>
41#include <fstream>
42#include <cstdarg>
43namespace raspicam {
44
49public:
50 static const int Generic=81799;
51};
52
53
54
55
59class Exception : public std::exception
60{
61public:
66 code = 0;
67 line = 0;
68 }
73 Exception(int _code, const std::string& _err, const std::string& _func, const std::string& _file, int _line)
74 : code(_code), err(_err), func(_func), file(_file), line(_line)
75 {
77 }
78 virtual ~Exception() throw() {}
79
83 virtual const char *what() const throw() {
84 return msg.c_str();
85 }
87 {
88 if ( func.size() > 0 )
89 msg = format("%s:%d: error: (%d) %s in function %s\n", file.c_str(), line, code, err.c_str(), func.c_str());
90 else
91 msg = format("%s:%d: error: (%d) %s\n", file.c_str(), line, code, err.c_str());
92 }
93
94 std::string msg;
95
96 int code;
97 std::string err;
98 std::string func;
99 std::string file;
100 int line;
101
102private:
103 std::string format( const char* fmt, ... )
104 {
105 char buf[1 << 16];
106 va_list args;
107 va_start( args, fmt );
108 vsprintf( buf, fmt, args );
109 return std::string(buf);
110 }
111};
112
113};
114#endif
Exception(int _code, const std::string &_err, const std::string &_func, const std::string &_file, int _line)
Definition exceptions.h:73
std::string func
function name. Available only when the compiler supports func macro
Definition exceptions.h:98
std::string file
source file name where the error has occured
Definition exceptions.h:99
std::string err
error description
Definition exceptions.h:97
int code
error code
Definition exceptions.h:96
std::string msg
the formatted error message
Definition exceptions.h:94
int line
line number in the source file where the error has occured
Definition exceptions.h:100
virtual const char * what() const
Definition exceptions.h:83
virtual ~Exception()
Definition exceptions.h:78
static const int Generic
Definition exceptions.h:50