Wider range of C# exceptions to throw. More applicable exceptions in are thrown.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6985 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6efd5eb6a0
commit
c83bd7f640
6 changed files with 173 additions and 65 deletions
|
|
@ -295,18 +295,18 @@ $1 = &temp; %}
|
|||
unsigned short {
|
||||
char error_msg[256];
|
||||
sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, error_msg);
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, error_msg);
|
||||
return $null;
|
||||
}
|
||||
|
||||
%typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY] %{
|
||||
(void)$1;
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, "C++ $1_type exception thrown");
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
|
||||
return $null;
|
||||
%}
|
||||
|
||||
%typemap(throws, canthrow=1) char * %{
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, $1);
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1);
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,56 +18,113 @@
|
|||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
/* Support for throwing C# exceptions from C/C++ */
|
||||
/* Support for throwing C# exceptions from C/C++. There are two types:
|
||||
* Exceptions that take a message and ArgumentExceptions that take a message and a parameter name. */
|
||||
typedef enum {
|
||||
SWIG_CSharpSystemException,
|
||||
SWIG_CSharpOutOfMemoryException,
|
||||
SWIG_CSharpIndexOutOfRangeException,
|
||||
SWIG_CSharpApplicationException,
|
||||
SWIG_CSharpArithmeticException,
|
||||
SWIG_CSharpDivideByZeroException,
|
||||
SWIG_CSharpArgumentOutOfRangeException,
|
||||
SWIG_CSharpNullReferenceException
|
||||
SWIG_CSharpIndexOutOfRangeException,
|
||||
SWIG_CSharpInvalidOperationException,
|
||||
SWIG_CSharpIOException,
|
||||
SWIG_CSharpNullReferenceException,
|
||||
SWIG_CSharpOutOfMemoryException,
|
||||
SWIG_CSharpOverflowException,
|
||||
SWIG_CSharpSystemException
|
||||
} SWIG_CSharpExceptionCodes;
|
||||
|
||||
typedef enum {
|
||||
SWIG_CSharpArgumentException,
|
||||
SWIG_CSharpArgumentNullException,
|
||||
SWIG_CSharpArgumentOutOfRangeException,
|
||||
} SWIG_CSharpExceptionArgumentCodes;
|
||||
|
||||
typedef void (SWIGSTDCALL* SWIG_CSharpExceptionCallback_t)(const char *);
|
||||
typedef void (SWIGSTDCALL* SWIG_CSharpExceptionArgumentCallback_t)(const char *, const char *);
|
||||
|
||||
typedef struct {
|
||||
SWIG_CSharpExceptionCodes code;
|
||||
SWIG_CSharpExceptionCallback_t callback;
|
||||
} SWIG_CSharpExceptions_t;
|
||||
} SWIG_CSharpException_t;
|
||||
|
||||
static SWIG_CSharpExceptions_t SWIG_csharp_exceptions[] = {
|
||||
{ SWIG_CSharpSystemException, NULL },
|
||||
{ SWIG_CSharpOutOfMemoryException, NULL },
|
||||
{ SWIG_CSharpIndexOutOfRangeException, NULL },
|
||||
typedef struct {
|
||||
SWIG_CSharpExceptionArgumentCodes code;
|
||||
SWIG_CSharpExceptionArgumentCallback_t callback;
|
||||
} SWIG_CSharpExceptionArgument_t;
|
||||
|
||||
static SWIG_CSharpException_t SWIG_csharp_exceptions[] = {
|
||||
{ SWIG_CSharpApplicationException, NULL },
|
||||
{ SWIG_CSharpArithmeticException, NULL },
|
||||
{ SWIG_CSharpDivideByZeroException, NULL },
|
||||
{ SWIG_CSharpIndexOutOfRangeException, NULL },
|
||||
{ SWIG_CSharpInvalidOperationException, NULL },
|
||||
{ SWIG_CSharpIOException, NULL },
|
||||
{ SWIG_CSharpNullReferenceException, NULL },
|
||||
{ SWIG_CSharpOutOfMemoryException, NULL },
|
||||
{ SWIG_CSharpOverflowException, NULL },
|
||||
{ SWIG_CSharpSystemException, NULL }
|
||||
};
|
||||
|
||||
static SWIG_CSharpExceptionArgument_t SWIG_csharp_exceptions_argument[] = {
|
||||
{ SWIG_CSharpArgumentException, NULL },
|
||||
{ SWIG_CSharpArgumentNullException, NULL },
|
||||
{ SWIG_CSharpArgumentOutOfRangeException, NULL },
|
||||
{ SWIG_CSharpNullReferenceException, NULL } };
|
||||
};
|
||||
|
||||
static void SWIG_CSharpSetPendingException(SWIG_CSharpExceptionCodes code, const char *msg) {
|
||||
SWIG_CSharpExceptionCallback_t callback = SWIG_csharp_exceptions[SWIG_CSharpSystemException].callback;
|
||||
if (code >=0 && (size_t)code < sizeof(SWIG_csharp_exceptions)/sizeof(SWIG_CSharpExceptions_t)) {
|
||||
SWIG_CSharpExceptionCallback_t callback = SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback;
|
||||
if (code >=0 && (size_t)code < sizeof(SWIG_csharp_exceptions)/sizeof(SWIG_CSharpException_t)) {
|
||||
callback = SWIG_csharp_exceptions[code].callback;
|
||||
}
|
||||
callback(msg);
|
||||
}
|
||||
|
||||
static void SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpExceptionArgumentCodes code, const char *msg, const char *param_name) {
|
||||
SWIG_CSharpExceptionArgumentCallback_t callback = SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback;
|
||||
if (code >=0 && (size_t)code < sizeof(SWIG_csharp_exceptions_argument)/sizeof(SWIG_CSharpExceptionArgument_t)) {
|
||||
callback = SWIG_csharp_exceptions_argument[code].callback;
|
||||
}
|
||||
callback(msg, param_name);
|
||||
}
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
DllExport void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(SWIG_CSharpExceptionCallback_t systemException,
|
||||
SWIG_CSharpExceptionCallback_t outOfMemory,
|
||||
SWIG_CSharpExceptionCallback_t indexOutOfRange,
|
||||
SWIG_CSharpExceptionCallback_t divideByZero,
|
||||
SWIG_CSharpExceptionCallback_t argumentOutOfRange,
|
||||
SWIG_CSharpExceptionCallback_t nullReference) {
|
||||
SWIG_csharp_exceptions[SWIG_CSharpSystemException].callback = systemException;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpOutOfMemoryException].callback = outOfMemory;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpIndexOutOfRangeException].callback = indexOutOfRange;
|
||||
DllExport void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(
|
||||
SWIG_CSharpExceptionCallback_t application,
|
||||
SWIG_CSharpExceptionCallback_t arithmetic,
|
||||
SWIG_CSharpExceptionCallback_t divideByZero,
|
||||
SWIG_CSharpExceptionCallback_t indexOutOfRange,
|
||||
SWIG_CSharpExceptionCallback_t invalidOperation,
|
||||
SWIG_CSharpExceptionCallback_t io,
|
||||
SWIG_CSharpExceptionCallback_t nullReference,
|
||||
SWIG_CSharpExceptionCallback_t outOfMemory,
|
||||
SWIG_CSharpExceptionCallback_t overflow,
|
||||
SWIG_CSharpExceptionCallback_t system) {
|
||||
SWIG_csharp_exceptions[SWIG_CSharpApplicationException].callback = application;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpArithmeticException].callback = arithmetic;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpDivideByZeroException].callback = divideByZero;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpArgumentOutOfRangeException].callback = argumentOutOfRange;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpIndexOutOfRangeException].callback = indexOutOfRange;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpInvalidOperationException].callback = invalidOperation;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpIOException].callback = io;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpNullReferenceException].callback = nullReference;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpOutOfMemoryException].callback = outOfMemory;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpOverflowException].callback = overflow;
|
||||
SWIG_csharp_exceptions[SWIG_CSharpSystemException].callback = system;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
DllExport void SWIGSTDCALL SWIGRegisterExceptionArgumentCallbacks_$module(
|
||||
SWIG_CSharpExceptionArgumentCallback_t argument,
|
||||
SWIG_CSharpExceptionArgumentCallback_t argumentNull,
|
||||
SWIG_CSharpExceptionArgumentCallback_t argumentOutOfRange) {
|
||||
SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentException].callback = argument;
|
||||
SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentNullException].callback = argumentNull;
|
||||
SWIG_csharp_exceptions_argument[SWIG_CSharpArgumentOutOfRangeException].callback = argumentOutOfRange;
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
@ -75,49 +132,100 @@ DllExport void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(SWIG_CSharpExc
|
|||
class SWIGExceptionHelper {
|
||||
|
||||
public delegate void ExceptionDelegate(string message);
|
||||
public delegate void ExceptionArgumentDelegate(string message, string paramName);
|
||||
|
||||
static ExceptionDelegate systemDelegate = new ExceptionDelegate(ThrowSystemException);
|
||||
static ExceptionDelegate outOfMemoryDelegate = new ExceptionDelegate(ThrowOutOfMemoryException);
|
||||
static ExceptionDelegate indexOutOfRangeDelegate = new ExceptionDelegate(ThrowIndexOutOfRangeException);
|
||||
static ExceptionDelegate applicationDelegate = new ExceptionDelegate(ThrowApplicationException);
|
||||
static ExceptionDelegate arithmeticDelegate = new ExceptionDelegate(ThrowArithmeticException);
|
||||
static ExceptionDelegate divideByZeroDelegate = new ExceptionDelegate(ThrowDivideByZeroException);
|
||||
static ExceptionDelegate argumentOutOfRangeDelegate = new ExceptionDelegate(ThrowArgumentOutOfRangeException);
|
||||
static ExceptionDelegate indexOutOfRangeDelegate = new ExceptionDelegate(ThrowIndexOutOfRangeException);
|
||||
static ExceptionDelegate invalidOperationDelegate = new ExceptionDelegate(ThrowInvalidOperationException);
|
||||
static ExceptionDelegate ioDelegate = new ExceptionDelegate(ThrowIOException);
|
||||
static ExceptionDelegate nullReferenceDelegate = new ExceptionDelegate(ThrowNullReferenceException);
|
||||
static ExceptionDelegate outOfMemoryDelegate = new ExceptionDelegate(ThrowOutOfMemoryException);
|
||||
static ExceptionDelegate overflowDelegate = new ExceptionDelegate(ThrowOverflowException);
|
||||
static ExceptionDelegate systemDelegate = new ExceptionDelegate(ThrowSystemException);
|
||||
|
||||
static ExceptionArgumentDelegate argumentDelegate = new ExceptionArgumentDelegate(ThrowArgumentException);
|
||||
static ExceptionArgumentDelegate argumentNullDelegate = new ExceptionArgumentDelegate(ThrowArgumentNullException);
|
||||
static ExceptionArgumentDelegate argumentOutOfRangeDelegate = new ExceptionArgumentDelegate(ThrowArgumentOutOfRangeException);
|
||||
|
||||
[DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionCallbacks_$module")]
|
||||
public static extern void SWIGRegisterExceptionCallbacks_$module(
|
||||
ExceptionDelegate systemExceptionDelegate,
|
||||
ExceptionDelegate outOfMemoryDelegate,
|
||||
ExceptionDelegate indexOutOfRangeDelegate,
|
||||
ExceptionDelegate divideByZeroDelegate,
|
||||
ExceptionDelegate argumentOutOfRangeDelegate,
|
||||
ExceptionDelegate nullReferenceDelegate);
|
||||
ExceptionDelegate applicationDelegate,
|
||||
ExceptionDelegate arithmeticDelegate,
|
||||
ExceptionDelegate divideByZeroDelegate,
|
||||
ExceptionDelegate indexOutOfRangeDelegate,
|
||||
ExceptionDelegate invalidOperationDelegate,
|
||||
ExceptionDelegate ioDelegate,
|
||||
ExceptionDelegate nullReferenceDelegate,
|
||||
ExceptionDelegate outOfMemoryDelegate,
|
||||
ExceptionDelegate overflowDelegate,
|
||||
ExceptionDelegate systemExceptionDelegate);
|
||||
|
||||
[DllImport("$dllimport", EntryPoint="SWIGRegisterExceptionArgumentCallbacks_$module")]
|
||||
public static extern void SWIGRegisterExceptionCallbacksArgument_$module(
|
||||
ExceptionArgumentDelegate argumentDelegate,
|
||||
ExceptionArgumentDelegate argumentNullDelegate,
|
||||
ExceptionArgumentDelegate argumentOutOfRangeDelegate);
|
||||
|
||||
static void ThrowApplicationException(string message) {
|
||||
SWIGPendingException.Set(new System.ApplicationException(message));
|
||||
}
|
||||
static void ThrowArithmeticException(string message) {
|
||||
SWIGPendingException.Set(new System.ArithmeticException(message));
|
||||
}
|
||||
static void ThrowDivideByZeroException(string message) {
|
||||
SWIGPendingException.Set(new System.DivideByZeroException(message));
|
||||
}
|
||||
static void ThrowIndexOutOfRangeException(string message) {
|
||||
SWIGPendingException.Set(new System.IndexOutOfRangeException(message));
|
||||
}
|
||||
static void ThrowInvalidOperationException(string message) {
|
||||
SWIGPendingException.Set(new System.InvalidOperationException(message));
|
||||
}
|
||||
static void ThrowIOException(string message) {
|
||||
SWIGPendingException.Set(new System.IO.IOException(message));
|
||||
}
|
||||
static void ThrowNullReferenceException(string message) {
|
||||
SWIGPendingException.Set(new System.NullReferenceException(message));
|
||||
}
|
||||
static void ThrowOutOfMemoryException(string message) {
|
||||
SWIGPendingException.Set(new System.OutOfMemoryException(message));
|
||||
}
|
||||
static void ThrowOverflowException(string message) {
|
||||
SWIGPendingException.Set(new System.OverflowException(message));
|
||||
}
|
||||
static void ThrowSystemException(string message) {
|
||||
SWIGPendingException.Set(new System.SystemException(message));
|
||||
}
|
||||
|
||||
static void ThrowOutOfMemoryException(string message) {
|
||||
SWIGPendingException.Set(new System.OutOfMemoryException(message));
|
||||
static void ThrowArgumentException(string message, string paramName) {
|
||||
SWIGPendingException.Set(new System.ArgumentException(message, paramName));
|
||||
}
|
||||
|
||||
static void ThrowIndexOutOfRangeException(string message) {
|
||||
SWIGPendingException.Set(new System.IndexOutOfRangeException(message));
|
||||
static void ThrowArgumentNullException(string message, string paramName) {
|
||||
SWIGPendingException.Set(new System.ArgumentNullException(paramName, message));
|
||||
}
|
||||
|
||||
static void ThrowDivideByZeroException(string message) {
|
||||
SWIGPendingException.Set(new System.DivideByZeroException(message));
|
||||
}
|
||||
|
||||
static void ThrowArgumentOutOfRangeException(string message) {
|
||||
SWIGPendingException.Set(new System.ArgumentOutOfRangeException(message));
|
||||
}
|
||||
|
||||
static void ThrowNullReferenceException(string message) {
|
||||
SWIGPendingException.Set(new System.NullReferenceException(message));
|
||||
static void ThrowArgumentOutOfRangeException(string message, string paramName) {
|
||||
SWIGPendingException.Set(new System.ArgumentOutOfRangeException(paramName, message));
|
||||
}
|
||||
|
||||
static SWIGExceptionHelper() {
|
||||
SWIGRegisterExceptionCallbacks_$module(systemDelegate, outOfMemoryDelegate, indexOutOfRangeDelegate, divideByZeroDelegate, argumentOutOfRangeDelegate, nullReferenceDelegate);
|
||||
SWIGRegisterExceptionCallbacks_$module(
|
||||
applicationDelegate,
|
||||
arithmeticDelegate,
|
||||
divideByZeroDelegate,
|
||||
indexOutOfRangeDelegate,
|
||||
invalidOperationDelegate,
|
||||
ioDelegate,
|
||||
nullReferenceDelegate,
|
||||
outOfMemoryDelegate,
|
||||
overflowDelegate,
|
||||
systemDelegate);
|
||||
|
||||
SWIGRegisterExceptionCallbacksArgument_$module(
|
||||
argumentDelegate,
|
||||
argumentNullDelegate,
|
||||
argumentOutOfRangeDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,8 +247,8 @@ DllExport void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(SWIG_CSharpExc
|
|||
}
|
||||
|
||||
public static void Set(Exception e) {
|
||||
if (pendingException != null) // Checks for missing pending exception code
|
||||
throw new Exception("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e); // unmanaged code destructors may not be called
|
||||
if (pendingException != null)
|
||||
throw new ApplicationException("FATAL: An earlier pending exception from unmanaged code was missed and thus not thrown (" + pendingException.ToString() + ")", e);
|
||||
pendingException = e;
|
||||
lock(typeof($modulePINVOKE)) {
|
||||
numExceptionsPending++;
|
||||
|
|
@ -200,5 +308,5 @@ DllExport void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_CSharpStringH
|
|||
|
||||
/* Contract support */
|
||||
|
||||
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_CSharpSetPendingException(SWIG_CSharpArgumentOutOfRangeException, msg); return nullreturn; } else
|
||||
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } else
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
%typemap(throws, canthrow=1) const enum SWIGTYPE & %{
|
||||
(void)$1;
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, "C++ $1_type exception thrown");
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@
|
|||
|
||||
%typemap(throws, canthrow=1) enum SWIGTYPE %{
|
||||
(void)$1;
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, "C++ $1_type exception thrown");
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
%typemap(throws, canthrow=1) const enum SWIGTYPE & %{
|
||||
(void)$1;
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, "C++ $1_type exception thrown");
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
|
||||
%typemap(throws, canthrow=1) enum SWIGTYPE %{
|
||||
(void)$1;
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, "C++ $1_type exception thrown");
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
%typemap(throws, canthrow=1) const enum SWIGTYPE & %{
|
||||
(void)$1;
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, "C++ $1_type exception thrown");
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
%typemap(throws, canthrow=1) enum SWIGTYPE %{
|
||||
(void)$1;
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, "C++ $1_type exception thrown");
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "C++ $1_type exception thrown");
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class string;
|
|||
%typemap(typecheck) string = char *;
|
||||
|
||||
%typemap(throws, canthrow=1) string %{
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, $1.c_str());
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.c_str());
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ class string;
|
|||
%typemap(typecheck) const string & = char *;
|
||||
|
||||
%typemap(throws, canthrow=1) const string & %{
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpSystemException, $1.c_str());
|
||||
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.c_str());
|
||||
return $null;
|
||||
%}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue