23
23
#include < stdexcept>
24
24
#include < vector>
25
25
26
+ #include < exception>
27
+
26
28
#include " mrcal_wrapper.h"
27
29
28
30
// JClass helper from wpilib
@@ -101,6 +103,17 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
101
103
102
104
} // extern "C"
103
105
106
+ static std::string what (const std::exception_ptr &eptr = std::current_exception())
107
+ {
108
+ if (!eptr) { throw std::bad_exception (); }
109
+
110
+ try { std::rethrow_exception (eptr); }
111
+ catch (const std::exception &e) { return e.what () ; }
112
+ catch (const std::string &e) { return e ; }
113
+ catch (const char *e) { return e ; }
114
+ catch (...) { return " who knows" ; }
115
+ }
116
+
104
117
/*
105
118
* Class: org_photonvision_mrcal_MrCalJNI_mrcal_1calibrate
106
119
* Method: 1camera
@@ -112,6 +125,9 @@ Java_org_photonvision_mrcal_MrCalJNI_mrcal_1calibrate_1camera
112
125
jint boardHeight, jdouble boardSpacing, jint imageWidth, jint imageHeight,
113
126
jdouble focalLenGuessMM)
114
127
{
128
+ try {
129
+
130
+
115
131
// Pull out arrays. We rely on data being packed and aligned to make this
116
132
// work! Observations should be [x, y, level]
117
133
std::span<mrcal_point3_t > observations{
@@ -197,6 +213,14 @@ Java_org_photonvision_mrcal_MrCalJNI_mrcal_1calibrate_1camera
197
213
rms_err, residuals, warp_x, warp_y, Noutliers);
198
214
199
215
return ret;
216
+
217
+ } catch (...) {
218
+ std::cerr << " Calibration exception: " << what () << std::endl;
219
+
220
+ static char buff[512 ];
221
+ strcpy (buff, what ().c_str ());
222
+ env->ThrowNew (env->FindClass (" java/lang/Exception" ), buff);
223
+ }
200
224
}
201
225
202
226
/*
0 commit comments