Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: v_borchert@despammed.com (Volker Borchert) Newsgroups: comp.lang.java.programmer Subject: Re: catch unsupported class version error Date: 2 Feb 2015 00:29:42 GMT Organization: Private site at Eddersheim, Germany Lines: 37 Distribution: world Message-ID: References: <54ceb004$0$283$14726298@news.sunsite.dk> X-Trace: individual.net UEa6yqO5yRH2bvhQPxEHJQr/7DwEtp+OM7p9yDC4ztT6AZWNhg Cancel-Lock: sha1:lqSbBZMFhodIkr4REIw0c4mEHRU= Xref: csiph.com comp.lang.java.programmer:30995 Arne Vajh??j wrote: > On 2/1/2015 5:49 PM, Philipp Kraus wrote: > > because within the source I use some 1.8 features e.g. thread-stealing pool. > > > > If I run the Jar on a version < 1.8 I get the error "unsupported > > major.minor version" with a stacktrace. > > > > IMHO I cannot catch the error, because it is thrown by a native method > > of the VM, I have found a solution, > > > > that I can compile a class with e.h. 1.7 option and check the running > > version of the VM and create an error > > > > message on a wrong version. > > > > I would like to create error like "You are need Java 1.8" and the user, > > which run's the Jar does not see the stacktrace. > > > > How can I do check the VM version and create a nice error message? > > Maybe: > System.getProperty("java.version") What about try { Class.forName("some.class.compiled.with.1_8") } catch (UnsupportedClassVersionError e) { ... } catch (ReflectiveOperationException e) { ... } -- "I'm a doctor, not a mechanic." Dr Leonard McCoy "I'm a mechanic, not a doctor." Volker Borchert