I made an application which take elf file(*.a and *.o) and give list of methods name, but if someone renames any file into *.a or *.o then it will show:
Exception occurred during event dispatching:
java.lang.NoClassDefFoundError: org/eclipse/core/resources/IWorkspaceRunnable
at org.eclipse.cdt.utils.AR.<init>(AR.java:237)
at com.lge.windowELF.ElfBinaryArchive.<init>(ElfBinaryArchive.java:24)
at com.lge.windowELF.ELFParserLibraryFile.createBinaryArchive(ELFParserLibraryFile.java:230)
at com.lge.windowELF.ELFParserLibraryFile.<init>(ELFParserLibraryFile.java:46)
at com.lge.windowELF.ELFWrapper.<init>(ELFWrapper.java:36)
at com.lge.windowELF.ELF_UIIntegrated.actionPerformed(ELF_UIIntegrated.java:510)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
In this situation I want to give some warning message. This exception is not caught by try/catch.
In the case of NoClassDefFoundError, the class was present at compile time, but Java runtime could not find it in Java classpath during runtime.
lang. NoClassDefFoundError, which means the Class Loader file responsible for dynamically loading classes can not find the . class file. So to remove this error, you should set your classpath to the location where your Class Loader is present.
ClassNotFoundException is a checked exception, so it has to be catch or thrown to the caller. ClassNotFoundException always occurs at runtime because we are indirectly loading the class using Classloader. Java compiler has no way to know if the class will be present in the classpath at runtime or not.
NoClassDefFoundError
is a subclass of Error
and not an Exception
. Hence you need to use:
try {
new org.eclipse.cdt.utils.AR();
}
catch(NoClassDefFoundError e) {
//handle carefully
}
in your code. Note that you shouldn't ever catch Error
or Throwable
. Also make sure that you surround as little code as possible with this catch
as this exception should not typically by caught.
UPDATE: Also are you sure you want to catch this exception? It is very rare and I can't imagine how do you want to handle it. Maybe you should just add a JAR with IWorkspaceRunnable
class to your CLASSPATH?
It's not encouraged to catch an Error
! JavaDoc states:
An
Error
is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.
My suggestion is that you sort out the NoClassDefFoundError
and worry about exceptions thrown by your code instead.
I would rather, in code, throw an InvalidELFFileException
(educated guess) on ElfBinaryArchive
constructor class (or wrap the class and do a throws
when instantiating) when the class tries to open the ELF file. That way, if there's an invalid ELF file, a decent exception is thrown.
Alternatively, make sure org.eclipse.core.resources.IWorkspaceRunnable
must be put in CLASSPATH.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With