File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes catch UnsupportedClassVersionError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "catch UnsupportedClassVersionError" Watch "catch UnsupportedClassVersionError" New topic
Author

catch UnsupportedClassVersionError

robin singal
Ranch Hand

Joined: Jul 18, 2007
Posts: 102
Hi

How can i handle the UnsupportedClassVersionError , I tried it using the below code which i first compiled in higher version and tried running it in lower version....


but can't handle .Can i handle the exception??


Life is short play hard.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9048
    
  10
It's not an Exception, it's an Error. You aren't really supposed to handle Errors ... they're usually fatal. In this case, the code (It doesn't really matter what handling you put in your code) won't run because of the error.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

No, you cannot catch that exception, because it's thrown when the class is loaded and before your code is executed.

You can use the "-source" and "-target" switches on the Java compiler to compile a class to an older version. That way, you can make a class that checks the Java version:

Compile this with:

javac -source 1.2 -target 1.2 TestJavaVersion.java

By using the switches, the Java compiler will create a class file that's compatible with Java 1.2 or newer.

(Note that the -source and -target switches are not a magic way to make your program run on any old Java version; if you use new language features or API classes that are not in the old version, it won't compile or run properly on the old version.)


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
robin singal
Ranch Hand

Joined: Jul 18, 2007
Posts: 102
Ya I got it thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: catch UnsupportedClassVersionError