I'm designing a solution, which includes a C++ library and several Java applications using the library via JNI.
C++ library allocates native memory massively. It's possible to detect from C++ code when this allocation fails. Failure to allocate should be reported to Java code with throwing something throwable.
The 2 options are considered:
- Throw java.lang.OutOfMemoryError from my C++ code
 - Add mylibrary.MyLibraryOutOfMemoryError (extends java.lang.RuntimeException or java.lang.Error), and throw it
 
What would be the right option and why?