JNI and Java violations

Source: Internet
Author: User
Tags exception handling stack trace

With JNI, you can discard, capture, print, and discard Java exceptions as you would in a Java program. But for programmers, it is necessary to invoke a dedicated JNI function to handle exceptions. Some of the JNI functions used for exception handling are listed below:
Throw (): Discards an existing exception object, which is used in the intrinsic method to discard an exception.
Thrownew (): Generates a new exception object and discards it.
Exceptionoccurred (): Determines if an exception has been discarded, but has not been cleared.
Exceptiondescribe (): Prints an exception and stack trace information.
Exceptionclear (): Clears a pending exception.
FatalError (): Causes a serious error and does not return.
Of all these functions, the most important thing to ignore is exceptionoccurred () and Exceptionclear (). Most JNI functions produce exceptions and do not have the language features that are available as they are in a try block in Java. So after each JNI function call, you must call Exceptionoccurred () to see if the exception has been discarded. If an exception is detected, you can choose to control it (and, if possible, discard it again). However, you must ensure that the exception is eventually cleared. This can be done in your own function using Exceptionclear (), and if the exception is discarded, it may be done in some other function. But in any case, this work is essential.
We must ensure that the anomaly is completely cleared. Otherwise, if you call a JNI function in an exception pending, the results are often unpredictable. There are also a few JNI functions that can be invoked safely in the case of exceptions, but they are all specialized exception control functions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.