Director exceptions now derive from std::exception

This commit is contained in:
William S Fulton 2014-01-20 19:40:52 +00:00
commit cc650e692e
10 changed files with 104 additions and 73 deletions

View file

@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.0 (in progress)
============================
2014-01-20: wsfulton
Director exceptions (Swig::DirectorException) now derive from std::exception
and hence provide the what() method. In Python and Ruby, this replaces the now
deprecated DirectorException::getMessage() method.
2014-01-16: wsfulton
[PHP] Fix compilation error in ZTS mode (64 bit windows) due to incorrect placement
of TSRMLS_FETCH() in SWIG_Php_GetModule() as reported by Mark Dawson-Butterworth.

View file

@ -9,6 +9,7 @@
#include <iostream>
#endif
#include <string>
#include <exception>
namespace Swig {
/* Director base class - not currently used in C# directors */
@ -16,7 +17,7 @@ namespace Swig {
};
/* Base class for director exceptions */
class DirectorException {
class DirectorException : public std::exception {
protected:
std::string swig_msg;
@ -27,16 +28,16 @@ namespace Swig {
DirectorException(const std::string &msg) : swig_msg(msg) {
}
const std::string& what() const {
return swig_msg;
virtual ~DirectorException() throw() {
}
virtual ~DirectorException() {
const char *what() const throw() {
return swig_msg.c_str();
}
};
/* Pure virtual method exception */
class DirectorPureVirtualException : public Swig::DirectorException {
class DirectorPureVirtualException : public DirectorException {
public:
DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempt to invoke pure virtual method ") + msg) {
}

View file

@ -9,6 +9,7 @@
#include <iostream>
#endif
#include <string>
#include <exception>
namespace Swig {
@ -17,28 +18,25 @@ namespace Swig {
};
// Base class for director exceptions.
class DirectorException {
class DirectorException : public std::exception {
protected:
std::string swig_msg;
public:
DirectorException(const char *msg) : swig_msg(msg) {
}
DirectorException(const std::string &msg) : swig_msg(msg) {
}
const std::string& what() const {
return swig_msg;
virtual ~DirectorException() throw() {
}
virtual ~DirectorException() {
const char *what() const throw() {
return swig_msg.c_str();
}
};
// Exception which is thrown when attempting to call a pure virtual method
// from D code thorugh the director layer.
class DirectorPureVirtualException : public Swig::DirectorException {
// from D code through the director layer.
class DirectorPureVirtualException : public DirectorException {
public:
DirectorPureVirtualException(const char *msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) {
}

View file

@ -1,8 +1,8 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes that proxy
* method calls from C++ to Java extensions.
* This file contains support for director classes so that Java proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION)

View file

@ -1,46 +1,47 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes that proxy
* method calls from C++ to Ocaml extensions.
*
* This file contains support for director classes so that Ocaml proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#include <string>
#include <exception>
# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG)
namespace Swig {
/* base class for director exceptions */
class DirectorException {
class DirectorException : public std::exception {
protected:
std::string swig_msg;
public:
DirectorException(const char *msg="") {
DirectorException(const char *msg="") : swig_msg(msg) {
}
const char *getMessage() const {
virtual ~DirectorException() throw() {
}
const char *what() const throw() {
return swig_msg.c_str();
}
virtual ~DirectorException() {
}
};
/* type mismatch in the return value from a python method call */
class DirectorTypeMismatchException : public Swig::DirectorException {
/* type mismatch in the return value from a Ocaml method call */
class DirectorTypeMismatchException : public DirectorException {
public:
DirectorTypeMismatchException(const char *msg="") {
DirectorTypeMismatchException(const char *msg="") : DirectorException(msg) {
}
};
/* any python exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException {};
/* any Ocaml exception that occurs during a director method call */
class DirectorMethodException : public DirectorException {};
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException {
class DirectorPureVirtualException : public DirectorException {
public:
DirectorPureVirtualException(const char *msg="") {
DirectorPureVirtualException(const char *msg="") : DirectorException(msg) {
}
static void raise(const char *msg) {

View file

@ -7,6 +7,8 @@
# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG)
#include <exception>
namespace Swig {
class Director {

View file

@ -1,8 +1,8 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes that proxy
* method calls from C++ to Perl extensions.
* This file contains support for director classes so that Perl proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#ifndef SWIG_DIRECTOR_PERL_HEADER_
@ -138,14 +138,13 @@ namespace Swig {
};
/* base class for director exceptions */
class DirectorException {
class DirectorException : public std::exception {
public:
virtual const char *getMessage() const = 0;
virtual SV *getNative() const = 0;
};
/* exceptions emitted by Perl */
class DirectorMethodException : public Swig::DirectorException {
class DirectorMethodException : public DirectorException {
protected:
SV *err;
public:
@ -153,11 +152,7 @@ namespace Swig {
SvREFCNT_inc(err);
}
~DirectorMethodException() {
SvREFCNT_dec(err);
}
const char *getMessage() const {
const char *what() const throw() {
return SvPV_nolen(err);
}
@ -169,15 +164,19 @@ namespace Swig {
throw DirectorMethodException(sv);
}
};
/* exceptions emitted by wrap code */
class DirectorWrapException : public Swig::DirectorException {
class DirectorWrapException : public DirectorException {
protected:
std::string msg;
DirectorWrapException(const char *str) : msg(str) {
}
public:
virtual const char *getMessage() const {
virtual ~DirectorWrapException() throw() {
}
const char *what() const throw() {
return msg.c_str();
}
@ -186,10 +185,11 @@ namespace Swig {
}
};
class DirectorTypeMismatchException : public Swig::DirectorWrapException {
class DirectorTypeMismatchException : public DirectorWrapException {
public:
DirectorTypeMismatchException(const char *str) : DirectorWrapException(str) {
}
static void raise(const char *type, const char *msg) {
std::string err = std::string(type);
err += ": ";
@ -198,12 +198,13 @@ namespace Swig {
}
};
class DirectorPureVirtualException : public Swig::DirectorWrapException {
class DirectorPureVirtualException : public DirectorWrapException {
public:
DirectorPureVirtualException(const char *name)
: DirectorWrapException("SWIG director pure virtual method called: ") {
msg += name;
}
static void raise(const char *name) {
throw DirectorPureVirtualException(name);
}

View file

@ -1,14 +1,15 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes that proxy
* method calls from C++ to PHP extensions.
* This file contains support for director classes so that PHP proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#ifndef SWIG_DIRECTOR_PHP_HEADER_
#define SWIG_DIRECTOR_PHP_HEADER_
#include <string>
#include <exception>
#include <map>
/*
@ -122,7 +123,7 @@ namespace Swig {
};
/* base class for director exceptions */
class DirectorException {
class DirectorException : public std::exception {
protected:
std::string swig_msg;
public:
@ -135,13 +136,20 @@ namespace Swig {
SWIG_ErrorMsg() = swig_msg.c_str();
}
virtual ~DirectorException() throw() {
}
const char *what() const throw() {
return swig_msg.c_str();
}
static void raise(int code, const char *hdr, const char *msg TSRMLS_DC) {
throw DirectorException(code, hdr, msg TSRMLS_CC);
}
};
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException {
class DirectorPureVirtualException : public DirectorException {
public:
DirectorPureVirtualException(const char *msg TSRMLS_DC)
: DirectorException(E_ERROR, "SWIG director pure virtual method called", msg TSRMLS_CC) {
@ -151,8 +159,9 @@ namespace Swig {
throw DirectorPureVirtualException(msg TSRMLS_CC);
}
};
/* any php exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException
class DirectorMethodException : public DirectorException
{
public:
DirectorMethodException(const char *msg TSRMLS_DC)

View file

@ -1,8 +1,8 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes that proxy
* method calls from C++ to Python extensions.
* This file contains support for director classes so that Python proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
#ifndef SWIG_DIRECTOR_PYTHON_HEADER_
@ -173,7 +173,7 @@ namespace Swig {
};
/* base class for director exceptions */
class DirectorException {
class DirectorException : public std::exception {
protected:
std::string swig_msg;
public:
@ -184,12 +184,20 @@ namespace Swig {
swig_msg += msg;
}
if (!PyErr_Occurred()) {
PyErr_SetString(error, getMessage());
PyErr_SetString(error, what());
}
SWIG_PYTHON_THREAD_END_BLOCK;
}
virtual ~DirectorException() throw() {
}
/* Deprecated, use what() instead */
const char *getMessage() const {
return what();
}
const char *what() const throw() {
return swig_msg.c_str();
}
@ -210,7 +218,7 @@ namespace Swig {
throw;
} catch (DirectorException& e) {
std::cerr << "SWIG Director exception caught:" << std::endl
<< e.getMessage() << std::endl;
<< e.what() << std::endl;
} catch (std::exception& e) {
std::cerr << "std::exception caught: "<< e.what() << std::endl;
} catch (...) {
@ -243,14 +251,14 @@ namespace Swig {
};
/* type mismatch in the return value from a python method call */
class DirectorTypeMismatchException : public Swig::DirectorException {
class DirectorTypeMismatchException : public DirectorException {
public:
DirectorTypeMismatchException(PyObject *error, const char *msg="")
: Swig::DirectorException(error, "SWIG director type mismatch", msg) {
: DirectorException(error, "SWIG director type mismatch", msg) {
}
DirectorTypeMismatchException(const char *msg="")
: Swig::DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg) {
: DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg) {
}
static void raise(PyObject *error, const char *msg) {
@ -263,7 +271,7 @@ namespace Swig {
};
/* any python exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException {
class DirectorMethodException : public DirectorException {
public:
DirectorMethodException(const char *msg = "")
: DirectorException(PyExc_RuntimeError, "SWIG director method error.", msg) {
@ -275,7 +283,7 @@ namespace Swig {
};
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException {
class DirectorPureVirtualException : public DirectorException {
public:
DirectorPureVirtualException(const char *msg = "")
: DirectorException(PyExc_RuntimeError, "SWIG director pure virtual method called", msg) {

View file

@ -1,8 +1,8 @@
/* -----------------------------------------------------------------------------
* director.swg
*
* This file contains support for director classes that proxy
* method calls from C++ to Ruby extensions.
* This file contains support for director classes so that Ruby proxy
* methods can be called from C++.
* ----------------------------------------------------------------------------- */
/*
@ -17,6 +17,7 @@
#include <string>
#include <iostream>
#include <exception>
#include <map>
# define SWIG_DIRECTOR_CAST(ARG) dynamic_cast<Swig::Director *>(ARG)
@ -108,7 +109,7 @@ namespace Swig {
};
/* Base class for director exceptions */
class DirectorException {
class DirectorException : public std::exception {
protected:
VALUE swig_error;
std::string swig_msg;
@ -130,6 +131,9 @@ namespace Swig {
}
public:
virtual ~DirectorException() throw() {
}
VALUE getType() const {
return CLASS_OF(swig_error);
}
@ -138,11 +142,13 @@ namespace Swig {
return swig_error;
}
/* Deprecated, use what() instead */
const std::string& getMessage() const {
return swig_msg;
}
virtual ~DirectorException() {
const char *what() const throw() {
return swig_msg.c_str();
}
};
@ -154,7 +160,7 @@ namespace Swig {
throw;
} catch (DirectorException& e) {
std::cerr << "SWIG Director exception caught:" << std::endl
<< e.getMessage() << std::endl;
<< e.what() << std::endl;
} catch (std::exception& e) {
std::cerr << "std::exception caught: "<< e.what() << std::endl;
} catch (...) {
@ -184,14 +190,14 @@ namespace Swig {
/* Type mismatch in the return value from a Ruby method call */
class DirectorTypeMismatchException : public Swig::DirectorException {
class DirectorTypeMismatchException : public DirectorException {
public:
DirectorTypeMismatchException(VALUE error, const char *msg="")
: Swig::DirectorException(error, "SWIG director type mismatch", msg) {
: DirectorException(error, "SWIG director type mismatch", msg) {
}
DirectorTypeMismatchException(const char *msg="")
: Swig::DirectorException(rb_eTypeError, "SWIG director type mismatch", msg) {
: DirectorException(rb_eTypeError, "SWIG director type mismatch", msg) {
}
static void raise(VALUE error, const char *msg) {
@ -204,14 +210,14 @@ namespace Swig {
};
/* Any Ruby exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException {
class DirectorMethodException : public DirectorException {
public:
DirectorMethodException(VALUE error)
: Swig::DirectorException(error) {
: DirectorException(error) {
}
DirectorMethodException(const char *msg = "")
: Swig::DirectorException(rb_eRuntimeError, "SWIG director method error.", msg) {
: DirectorException(rb_eRuntimeError, "SWIG director method error.", msg) {
}
static void raise(VALUE error) {
@ -220,7 +226,7 @@ namespace Swig {
};
/* Attempted to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException
class DirectorPureVirtualException : public DirectorException
{
public:
DirectorPureVirtualException(const char *msg = "")