• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

catch UnsupportedClassVersionError

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
robin singal
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya I got it thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic