File: hdfexceptionImp.c

package info (click to toggle)
nexus 4.4.3-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,864 kB
  • sloc: cpp: 34,928; ansic: 17,317; f90: 2,326; xml: 2,071; java: 1,953; fortran: 1,529; python: 766; makefile: 532; sh: 460; tcl: 173; lisp: 169
file content (166 lines) | stat: -rw-r--r-- 3,726 bytes parent folder | download | duplicates (5)
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

/****************************************************************************
 * NCSA HDF                                                                 *
 * National Comptational Science Alliance                                   *
 * University of Illinois at Urbana-Champaign                               *
 * 605 E. Springfield, Champaign IL 61820                                   *
 *                                                                          *
 * For conditions of distribution and use, see the accompanying             *
 * hdf/COPYING file.                                                        *
 *                                                                          *
 ****************************************************************************/

/*
 *  This is a utility program used by the HDF Java-C wrapper layer to
 *  generate exceptions.  This may be called from any part of the
 *  Java-C interface.
 *
 */

#include <stdio.h>
#include "jni.h"
#include "hdfexceptionImp.h"

jboolean buildException( JNIEnv *env, jint HDFerr)
{
jmethodID jm;
jclass jc;
int args[2];
jobject ex;
int rval;


	jc = (*env)->FindClass(env, "ncsa/hdf/hdflib/HDFLibraryException");
	if (jc == NULL) {
		return JNI_FALSE;
	}
	jm = (*env)->GetMethodID(env, jc, "<init>", "(I)V");
	if (jm == NULL) {
		return JNI_FALSE;
	}
	args[0] = HDFerr;
	args[1] = 0;

	ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );

	rval = (*env)->Throw(env, ex );

	return JNI_TRUE;
}

jboolean NotImplemented( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;


	jc = (*env)->FindClass(env, "ncsa/hdf/hdflib/HDFNotImplementedException");
	if (jc == NULL) {
		return JNI_FALSE;
	}
	jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
	if (jm == NULL) {
		return JNI_FALSE;
	}

	str = (*env)->NewStringUTF(env,functName);
	args[0] = (char *)str;
	args[1] = 0;
	ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );

	rval = (*env)->Throw(env, ex );

	return JNI_TRUE;
}

jboolean outOfMemory( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;

	jc = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
	if (jc == NULL) {
		return JNI_FALSE;
	}
	jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
	if (jm == NULL) {
		return JNI_FALSE;
	}

	str = (*env)->NewStringUTF(env,functName);
	args[0] = (char *)str;
	args[1] = 0;
	ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );

	rval = (*env)->Throw(env, ex );

	return JNI_TRUE;
}


/*
 *  A fatal error in a JNI call
 */
jboolean JNIFatalError( JNIEnv *env, char *functName)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;

	jc = (*env)->FindClass(env, "java/lang/InternalError");
	if (jc == NULL) {
		return JNI_FALSE;
	}
	jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
	if (jm == NULL) {
		return JNI_FALSE;
	}

	str = (*env)->NewStringUTF(env,functName);
	args[0] = (char *)str;
	args[1] = 0;
	ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );

	rval = (*env)->Throw(env, ex );

	return JNI_TRUE;
}

jboolean raiseException( JNIEnv *env, char *message)
{
jmethodID jm;
jclass jc;
char * args[2];
jobject ex;
jstring str;
int rval;

	jc = (*env)->FindClass(env, "ncsa/hdf/hdflib/HDFLibraryException");
	if (jc == NULL) {
		return JNI_FALSE;
	}
	jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
	if (jm == NULL) {
		return JNI_FALSE;
	}

	str = (*env)->NewStringUTF(env,message);
	args[0] = (char *)str;
	args[1] = 0;
	ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );

	rval = (*env)->Throw(env, ex );

	return JNI_TRUE;
}