@@ -49,13 +49,42 @@ using pdal::PointViewLess;
4949using pdal::PointViewPtr;
5050using pdal::pdal_error;
5151
52- JNIEXPORT void JNICALL Java_io_pdal_Pipeline_initialise
52+ jstring throwInitializationException (JNIEnv *env, const char *message)
53+ {
54+ jclass Exception = env->FindClass (" io/pdal/InitializationException" );
55+ env->ThrowNew (Exception, message);
56+ return env->NewStringUTF (message);
57+ }
58+
59+ jstring throwExecutionException (JNIEnv *env, const char *message)
60+ {
61+ jclass Exception = env->FindClass (" io/pdal/ExecutionException" );
62+ env->ThrowNew (Exception, message);
63+ return env->NewStringUTF (message);
64+ }
65+
66+ JNIEXPORT void JNICALL Java_io_pdal_Pipeline_initialize
5367 (JNIEnv *env, jobject obj)
5468{
5569 jclass c = env->GetObjectClass (obj);
5670 jfieldID fid = env->GetFieldID (c, " json" , " Ljava/lang/String;" );
5771 jstring jstr = reinterpret_cast <jstring>(env->GetObjectField (obj, fid));
58- setHandle (env, obj, new Pipeline (std::string (env->GetStringUTFChars (jstr, 0 ))));
72+
73+ if (jstr == NULL )
74+ {
75+ throwInitializationException (env, " Null string passed into the Pipeline constructor." );
76+ }
77+ else
78+ {
79+ try
80+ {
81+ setHandle (env, obj, new Pipeline (std::string (env->GetStringUTFChars (jstr, 0 ))));
82+ }
83+ catch (const pdal_error &pe)
84+ {
85+ throwInitializationException (env, pe.what ());
86+ }
87+ }
5988}
6089
6190JNIEXPORT void JNICALL Java_io_pdal_Pipeline_dispose
@@ -70,21 +99,42 @@ JNIEXPORT void JNICALL Java_io_pdal_Pipeline_execute
7099 (JNIEnv *env, jobject obj)
71100{
72101 Pipeline *p = getHandle<Pipeline>(env, obj);
73- p->execute ();
102+ try
103+ {
104+ p->execute ();
105+ }
106+ catch (const pdal_error &pe)
107+ {
108+ throwExecutionException (env, pe.what ());
109+ }
74110}
75111
76112JNIEXPORT jstring JNICALL Java_io_pdal_Pipeline_getMetadata
77113 (JNIEnv *env, jobject obj)
78114{
79- Pipeline *p = getHandle<Pipeline>(env, obj);
80- return env->NewStringUTF (p->getMetadata ().c_str ());
115+ try
116+ {
117+ Pipeline *p = getHandle<Pipeline>(env, obj);
118+ return env->NewStringUTF (p->getMetadata ().c_str ());
119+ }
120+ catch (const pdal_error &pe)
121+ {
122+ return throwExecutionException (env, pe.what ());
123+ }
81124}
82125
83126JNIEXPORT jstring JNICALL Java_io_pdal_Pipeline_getSchema
84127 (JNIEnv *env, jobject obj)
85128{
86- Pipeline *p = getHandle<Pipeline>(env, obj);
87- return env->NewStringUTF (p->getSchema ().c_str ());
129+ try
130+ {
131+ Pipeline *p = getHandle<Pipeline>(env, obj);
132+ return env->NewStringUTF (p->getSchema ().c_str ());
133+ }
134+ catch (const pdal_error &pe)
135+ {
136+ return throwExecutionException (env, pe.what ());
137+ }
88138}
89139
90140JNIEXPORT jboolean JNICALL Java_io_pdal_Pipeline_validate
@@ -129,16 +179,23 @@ JNIEXPORT jstring JNICALL Java_io_pdal_Pipeline_getLog
129179JNIEXPORT jobject JNICALL Java_io_pdal_Pipeline_getPointViews
130180 (JNIEnv *env, jobject obj)
131181{
132- Pipeline *p = getHandle<Pipeline>(env, obj);
133- PointViewSet pvset = p->getPointViews ();
182+ try
183+ {
184+ Pipeline *p = getHandle<Pipeline>(env, obj);
185+ PointViewSet pvset = p->getPointViews ();
134186
135- jclass pviClass = env->FindClass (" io/pdal/PointViewIterator" );
136- jmethodID pviCtor = env->GetMethodID (pviClass, " <init>" , " ()V" );
137- jobject pvi = env->NewObject (pviClass, pviCtor);
187+ jclass pviClass = env->FindClass (" io/pdal/PointViewIterator" );
188+ jmethodID pviCtor = env->GetMethodID (pviClass, " <init>" , " ()V" );
189+ jobject pvi = env->NewObject (pviClass, pviCtor);
138190
139- PointViewIterator *it = new PointViewIterator (pvset);
191+ PointViewIterator *it = new PointViewIterator (pvset);
140192
141- setHandle (env, pvi, it);
193+ setHandle (env, pvi, it);
142194
143- return pvi;
195+ return pvi;
196+ }
197+ catch (const libpdaljava::java_error &je)
198+ {
199+ return throwExecutionException (env, je.what ());
200+ }
144201}
0 commit comments