On Fri, 28 Jul 2023 08:02:22 GMT, Matthias Baesken <[email protected]> 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

Reply via email to