summaryrefslogtreecommitdiffstats
path: root/scilab/modules/action_binding/src/jni/GiwsException.hxx
blob: cdde15a9e78f124eb001d103f1a38e7537444282 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/* Generated by GIWS (version 1.0.4) */
/*

Copyright 2007-2008 INRIA

Author : Sylvestre Ledru & others

This software is a computer program whose purpose is to hide the complexity
of accessing Java objects/methods from C++ code.

This software is governed by the CeCILL-B license under French law and
abiding by the rules of distribution of free software.  You can  use, 
modify and/ or redistribute the software under the terms of the CeCILL-B
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info". 

As a counterpart to the access to the source code and  rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty  and the software's author,  the holder of the
economic rights,  and the successive licensors  have only  limited
liability. 

In this respect, the user's attention is drawn to the risks associated
with loading,  using,  modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean  that it is complicated to manipulate,  and  that  also
therefore means  that it is reserved for developers  and  experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or 
data to be ensured and,  more generally, to use and operate it in the 
same conditions as regards security. 

The fact that you are presently reading this means that you have had
knowledge of the CeCILL-B license and that you accept its terms.
*/


#ifndef __GIWSEXCEPTION__
#define __GIWSEXCEPTION__
#include <iostream>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <jni.h>
#include <exception>

namespace GiwsException {


/**
* Parent class for exceptions which may occure in JNI code.
*/
class JniException : public std::exception
{

/** Error message to display */
std::string m_oErrorMessage;

/** Java description of the exception*/
std::string m_oJavaMessage;

/** Java stackTrace when the exception occured */
std::string m_oJavaStackTrace;

/** Name of the exception (ie class name).*/
std::string m_oJavaExceptionName;

/** The exception itself ... we store as a member otherwise JNI
complains about 'WARNING in native method: JNI call made with
exception pending' */
jthrowable javaException;

public:

/**
* Each subclass of JniExcpetion should call the super constructor
* and the setErrorMessage function to set the message.
* @param curEnv java environment where the exception occured.
*/
JniException(JNIEnv * curEnv) throw() ;

virtual ~JniException(void) throw();

/**
* @return a description of the exception
*/
virtual const char * what(void) const throw();

/**
* @return Java description of the exception.
*/
std::string getJavaDescription(void) const throw();

/**
* @return Java stack trace where the exception occured.
*/
std::string getJavaStackTrace(void) const throw();

/**
* Get the name of the exception (ie its class name).
*/
std::string getJavaExceptionName(void) const throw();

protected:

/**
* Set the error message that the exception should print.
*/
void setErrorMessage(const std::string & errorMessage);

/**
* Get the message that the exception will print.
*/
std::string getErrorMessage(void) const;

private:
  /**
* @return error message of the exception.
*/
std::string retrieveExceptionMessage(JNIEnv * curEnv);
/**
* @return full stack trace when the exception occured.
*/
std::string retrieveStackTrace(JNIEnv * curEnv);

/**
* @return string containing the name of the exception (ie its class name).
*/
std::string retrieveExceptionName(JNIEnv * curEnv);
/**
* To be called when all the information about the exceptions have been
* retrived.
* Remove the exception from the environment.
*/
void closeException(JNIEnv * curEnv);

/**
* Convert a Java string (jstring) into a C++ string
*/
std::string convertJavaString(JNIEnv * curEnv, jstring javaString);
};

/**
* Exception that should be thrown when allocation of Java ressources from C++
* code fails (sur as NewDoubleArray or NewStringUTF).
*/
class JniBadAllocException : public JniException
{
public:

JniBadAllocException(JNIEnv * curEnv) throw();
virtual ~JniBadAllocException(void) throw();
};

/**
* Exception that should be thrown when a call to a Java method
* using Jni throw an exception.
* If possible, user should try to avoid this sitution because of the loss
* of information.
*/
class JniCallMethodException : public JniException
{
public:

  /**
   * @param curEnv java envirnonment where the exception occured.
   */
  JniCallMethodException(JNIEnv * curEnv) throw();

  virtual ~JniCallMethodException(void) throw();
};

/**
* Exception that should be thrown when Jni code could not find a Java class
*/
class JniClassNotFoundException : public JniException
{
public:

/**
* @param className name of the class which haven't been found
*/
JniClassNotFoundException(JNIEnv * curEnv, const std::string & className) throw();

virtual ~JniClassNotFoundException(void) throw();

};

/**
* Exception that should be thrown when Jni code could not find a Java method
*/
class JniMethodNotFoundException : public JniException
{
public:

/**
* @param className name of the method which haven't been found
*/
JniMethodNotFoundException(JNIEnv * curEnv, const std::string & methodName) throw();
virtual ~JniMethodNotFoundException(void) throw();

};

/**
* Exception that should be thrown when a call to a Java method
* using Jni throw an exception.
* If possible, user should try to avoid this sitution because of the loss
* of information.
*/
class JniObjectCreationException : public JniException
{
public:

/**
* @param curEnv java envirnonment where the exception occured.
*/
JniObjectCreationException(JNIEnv * curEnv, const std::string & className) throw();
virtual ~JniObjectCreationException(void) throw();

};


/**
* Exception that should be thrown when a call to the Java monitor
* failed
*/
class JniMonitorException : public JniException
{
public:

/**
* @param curEnv java envirnonment where the exception occured.
*/
JniMonitorException(JNIEnv * curEnv, const std::string & className) throw();
virtual ~JniMonitorException(void) throw();

};


}
#endif