On Sat, 8 Feb 2025 04:02:08 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:

> It would be good to check what type of exception the methods chain can throw, 
> is it only std::bad_alloc()? if yes, then we can use TRY + CATCH_BAD_ALLOC. 
> If we can get another exception, we should figure out how we can report this 
> error to the user.

In `CreateIconFromRaster` a catch-all construct is used, and then the exception 
is re-thrown:

https://github.com/openjdk/jdk/blob/ab66c82ce9fdb5ee3fd7690f42b8ad4d78bf5e40/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp#L2082-L2087

At the same time, `BitmapUtil::CreateTransparencyMaskFromARGB` may throw only 
`std::bad_alloc` at

https://github.com/openjdk/jdk/blob/ab66c82ce9fdb5ee3fd7690f42b8ad4d78bf5e40/src/java.desktop/windows/native/libawt/windows/awt_BitmapUtil.cpp#L43

where `SAFE_SIZE_NEW_ARRAY2` is defined as

https://github.com/openjdk/jdk/blob/ab66c82ce9fdb5ee3fd7690f42b8ad4d78bf5e40/src/java.desktop/share/native/common/awt/utility/sizecalc.h#L93-L95

Thus, after looking at the chain of calls, `std::bad_alloc` is the only C++ 
exception that may ever be thrown.

Then, the pair of 
[`TRY`](https://github.com/openjdk/jdk/blob/ab66c82ce9fdb5ee3fd7690f42b8ad4d78bf5e40/src/java.desktop/windows/native/libawt/windows/alloc.h#L131-L134)
 and 
[`CATCH_BAD_ALLOC`](https://github.com/openjdk/jdk/blob/ab66c82ce9fdb5ee3fd7690f42b8ad4d78bf5e40/src/java.desktop/windows/native/libawt/windows/alloc.h#L154-L160)
 could be a better alternative.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23470#issuecomment-2648827456

Reply via email to