]> git.sesse.net Git - mlt/blob - src/modules/kino/error.cc
Initial version
[mlt] / src / modules / kino / error.cc
1 /*
2 * error.cc Error handling
3 * Copyright (C) 2000 Arne Schirmacher <arne@schirmacher.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 // C++ includes
25
26 #include <string>
27 #include <iostream>
28 #include <sstream>
29 #include <iomanip>
30
31 using std::ostringstream;
32 using std::string;
33 using std::endl;
34 using std::ends;
35 using std::cerr;
36
37 // C includes
38
39 #include <errno.h>
40 #include <string.h>
41
42 // local includes
43
44 #include "error.h"
45
46 void real_fail_neg( int eval, const char *eval_str, const char *func, const char *file, int line )
47 {
48         if ( eval < 0 )
49         {
50                 string exc;
51                 ostringstream sb;
52
53                 sb << file << ":" << line << ": In function \"" << func << "\": \"" << eval_str << "\" evaluated to " << eval;
54                 if ( errno != 0 )
55                         sb << endl << file << ":" << line << ": errno: " << errno << " (" << strerror( errno ) << ")";
56                 sb << ends;
57                 exc = sb.str();
58                 cerr << exc << endl;
59                 throw exc;
60         }
61 }
62
63
64 /** error handler for NULL result codes
65  
66     Whenever this is called with a NULL argument, it will throw an
67     exception. Typically used with functions like malloc() and new().
68  
69 */
70
71 void real_fail_null( const void *eval, const char *eval_str, const char *func, const char *file, int line )
72 {
73         if ( eval == NULL )
74         {
75
76                 string exc;
77                 ostringstream sb;
78
79                 sb << file << ":" << line << ": In function \"" << func << "\": " << eval_str << " is NULL" << ends;
80                 exc = sb.str();
81                 cerr << exc << endl;
82                 throw exc;
83         }
84 }
85
86
87 void real_fail_if( bool eval, const char *eval_str, const char *func, const char *file, int line )
88 {
89         if ( eval == true )
90         {
91
92                 string exc;
93                 ostringstream sb;
94
95                 sb << file << ":" << line << ": In function \"" << func << "\": condition \"" << eval_str << "\" is true";
96                 if ( errno != 0 )
97                         sb << endl << file << ":" << line << ": errno: " << errno << " (" << strerror( errno ) << ")";
98                 sb << ends;
99                 exc = sb.str();
100                 cerr << exc << endl;
101                 throw exc;
102         }
103 }