RFR: JDK-8313164: src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp GetRGBPixels adjust releasing of resources [v2]
Alexey Ivanov
aivanov at openjdk.org
Fri Jul 28 12:14:03 UTC 2023
On Fri, 28 Jul 2023 08:02:22 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:
>> src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp line 207:
>>
>>> 205: ::DeleteDC(hdcScreen);
>>> 206: throw std::bad_alloc();
>>> 207: }
>>
>> I wonder if we can catch `std::bad_alloc` to release the resources and to re-throw the exception.
>>
>> Since a C++ exception is thrown, using try-catch for clean-up seems reasonable, this would avoid duplicating the clean-up code in three places or so.
>
> Hi Alexey, probably we could do this. Do you think it is worth the effort (we would have a big try catch block instead, but would centralize the ::Delete* calls) ?
Since you've already integrated, it's not worth redoing in my opinion.
Error handling in C and C++ code is always prone to repetitive sequence of calls; in this particular case exceptions are already used, and it looks that handling that exception could have had a benefit of reducing code duplication.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15038#discussion_r1277472496
More information about the client-libs-dev
mailing list