File: exceptions.h

package info (click to toggle)
python-visual 3.2.9-4.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,796 kB
  • ctags: 2,664
  • sloc: cpp: 11,958; sh: 8,185; python: 3,709; ansic: 480; makefile: 311
file content (49 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download
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
#ifndef VISUAL_EXCEPTIONS_H
#define VISUAL_EXCEPTIONS_H

// Copyright (c) 2000, 2001, 2002, 2003 by David Scherer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.

#include <exception>
#include <boost/python/detail/wrap_python.hpp>

namespace visual { namespace python {

/* Base class for pythonic exceptions.  Some functions that check their arguments
 * may throw a subclass of Exception.  All of these exceptions are automatically translated to python
 * at the python/C++ barrier.  If one of these is caught and not propogated, no special action
 * needs to be taken to clear the exception (since python never saw it).
 * Each of these have a direct 1:1 conversion to python. 
 */
class Exception : public std::exception
{
 protected:
	char const* error;
	inline Exception() : error(0) {}
	
 public:
	inline Exception( char const* str) : error(str) {}
	inline Exception( const Exception& other) : exception(other), error( other.error) {}
	
	inline const char* what( void) const throw()
	{ return error; }
	
	// Called by the translator to raise the appropriate python exception.
	virtual void raise();
};

class ZeroDivisionError : public Exception
{
 public:
 	inline ZeroDivisionError( const char* str) : Exception( str) {}
 	inline ZeroDivisionError() : Exception( NULL) {}
 	virtual void raise();
	
};

void translate_exception( Exception e);
	
}} // !namespace visual::python

#endif // !VISUAL_BOOSTEXCEPTION_H