File: exception.h

package info (click to toggle)
dynare 4.4.3-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 41,356 kB
  • ctags: 15,842
  • sloc: cpp: 77,029; ansic: 29,056; pascal: 13,241; sh: 4,811; objc: 3,061; yacc: 3,013; makefile: 1,479; lex: 1,258; python: 162; lisp: 54; xml: 8
file content (55 lines) | stat: -rw-r--r-- 1,182 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) 2005, Ondra Kamenik

// $Id: exception.h 1367 2007-07-11 14:21:57Z kamenik $

#ifndef OGU_EXCEPTION_H
#define OGU_EXCEPTION_H

#include <cstdio>
#include <cstring>

#include <string>
#include <algorithm>

namespace ogu {

	/** A primitive exception. */
	class Exception {
		static const int file_length = 100;
		static const int mes_length = 500;
	protected:
		char file[file_length];
		int line;
		char mes[mes_length];
	public:
		Exception(const char* f, int l, const char* m)
			{
				strncpy(file, f, file_length-1);
				file[file_length-1] = '\0';
				line = l;
				strncpy(mes, m, std::min(mes_length-1,(int)strlen(m)));
				mes[mes_length-1] = '\0';
			}
		Exception(const char* f, int l, const std::string& m)
			{
				strncpy(file, f, file_length-1);
				file[file_length-1] = '\0';
				line = l;
				strncpy(mes, m.c_str(), std::min(mes_length-1,(int)m.length()));
				mes[mes_length-1] = '\0';
			}
		virtual ~Exception() {}
		void print(FILE* fd) const
			{ fprintf(fd, "%s:%d: %s\n", file, line, mes); }
		void print() const
			{ print(stdout); }
		const char* message() const
			{ return mes; }
	};
};

#endif

// Local Variables:
// mode:C++
// End: