Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Can someone give a code example where each is thrown?</p> </blockquote> <p>The <code>IllegalAccessException</code> is thrown when you try to use reflection to invoke a method or read or write a field that is forbidden by the Java visibility rules.</p> <p>An <code>IllegalAccessError</code> cannot be thrown by consistently compiled Java code. It occurs when for example, you load a class that attempts to invoke a method or read or write a field in another class that is forbidden by the Java visibility rules. This is something that the compiler would normally prevent, so this means there is something seriously wrong with the classes. At any rate, this is considered to be an "error"; i.e. not recoverable, and the classloader will refuse to load the offending class(es).</p> <blockquote> <p>Does the similarity in name imply relationship between the two, or is it just pure coincidence?</p> </blockquote> <p>There is a clear relationship between the two. The difference is the circumstances in which the two occur.</p> <blockquote> <p>Are there other XXXError and XXXException combo? How are the pairs related to each other?</p> </blockquote> <p>Pass. Check the javadocs.</p> <blockquote> <p>If you explicitly try to catch one in an Exception/Error pair, should you also catch the other?</p> </blockquote> <p>Probably not. The XXXError and XXXException generally occur in different circumstances. (This certainly applies to the reflective vs. classloader ones.) </p> <p>Besides, as a general rule you should not attempt to catch and recover from subtypes of <code>Error</code>. The whole point of separating <code>Error</code> from <code>Exception</code> is to distinguish the non-recoverable and (potentially) recoverable exceptions.</p> <p>In this case, there is nothing that a normal application can do in the way of recovering from the <code>IllegalAccessError</code>. If you attempt to repeat the classloader operation that caused the problem, it will just happen again.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload