Regis wrote: > I have attached a patch for this issue on JIRA. See comments elsewhere why the patch needs some tweaking.
> I think that would be helpful to add file path in error messages when > throw FileNotFoundException, and that need to allocate new memory for > the new messages, I used hymem_allocate_memory to do this. But I don't > have chance to free that memory, since exception thrown, code back to > java. That may cause memory leak, I know define a enough large char > array could avoid this, but need more memory (path may be very long), is > there any other better way to do this? Thanks! A code sample would be helpful to ensure I understand your situation correctly. But the 'throw' in native code does not cause a function return (think of it as marking a pending throw upon return [1]). The ThrowNew JNI call will copy the message string into a new Java String object, so you can free it before the native returns, i.e. allocate memory throw exception free memory return from native (causes throw to occur) Of course, you can also just use a local var rather than allocate if you want too. Make sense? Tim [1] It's important to understand this, otherwise you'll be surprised about code running after your "native throw". As a rule, you should tidy-up and return quite soon after raising the exception for clarity.
