[Development] Make Qt6 JNI API safer to use

Vitaly Fanaskov vitaly.fanaskov at qt.io
Fri Mar 6 11:10:00 CET 2020


Regarding exceptions, I see your point. Personally I agree with using 
exceptions here. If there are no well justified objections, just go for it.

On 3/5/20 4:59 PM, Bogdan Vatra wrote:
> Hi,
>
> În ziua de joi, 5 martie 2020, la 17:14:44 EET, Vitaly Fanaskov a scris:
>> I think something like std::expected is a nice thing to have.
>>
>> There is some experimental implementation of std::expected:
>> https://github.com/TartanLlama/expected.
>>
> That implementation is my favorite, I really like the map, map_error,
> and_then, or_else additions ;-) .
>
> [...]
>> Regarding using exceptions, well, I would vote for this option, but I
>> don't think that this is possible at all to convince people to use
>> exceptions in this module.
>>
> A single Qt JNI call might fail in different places, e.g.:
> auto str1 = QAndroidJniObject::callStaticObjectMethod("MyClass",
> 		"fromNumber",
>                                                 "(I)Ljava/lang/String;",
>                                                 10);
>
> 1. check if there is any pending exceptions on current JNI Env
> 2. check if the method signature is okay
> 3. check if the method call throw any exceptions
>
> Using exceptions we can pinpoint what happened.
>
> Imagine how hard will be without exceptions to pass as parameters more jni
> methods/fields results ...
>
> Cheers,
> BogDan.
>
-- 
Best Regards,

Fanaskov Vitaly
Senior Software Engineer

The Qt Company



More information about the Development mailing list