0

I found a really weird bug within my Java Code Even when i force a RuntimeException in my program it is not recognized by the JVM.

Here a demo of what I have written

private static void someMethod(){
   //Some Code
     if(true)
       throw new RuntimeException();
  // More Code
}

I added the if(true) to prevent the unreachable code message, just for testing. But I think that the real problem is that there is some unhandled Exception in my code, which I cant really log, because the printStackTrace() is missing, or else i should get a console log. Also I get the plain text: Exception while removing reference. But its no System.err message, it just look like System.out

Are there any other methods of logging exception, excpect the default console, and what could cause a exception to be unhandled?

NOTE: I use following external libraries: JNativeHook, JLayer, Apache Commons IO

Full GitHub repo The Exception should occur in CsgoSounds.java at line 944

OS: Windows 10, jre version: 1.8.0_60

Einstein
  • 360
  • 1
  • 4
  • 15
  • 1
    there are tons of options. consoles, logging-libraries, ... –  Sep 11 '15 at 11:13
  • Yes, but the problem is that I have a previous exception, which seems to be unhandled, and therefore I dont think console logging would work. – Einstein Sep 11 '15 at 11:14
  • Where do you expect to view the exception? Or more specific: on which 'console'? Are you running eclipse / intelli / any other IDE, or tracking the command line? – bully Sep 11 '15 at 11:20
  • @Einstein, i guess the real problem is that unhandled exception. This can't be handled by any kind of logging. Instead try launching the app via commandline to get the stacktrace of the unhandled exception –  Sep 11 '15 at 11:20
  • @bully I am compiling on Eclipse and also use the Eclipse console for logging. The windows console would print the same output because JVM calls System.err Stream when a RuntimeException occurs – Einstein Sep 11 '15 at 11:23
  • I can't clone right now, but may it be you are running into / observing something similiar like this: http://stackoverflow.com/questions/2873449/occasional-interruptedexception-when-quitting-a-swing-application? – bully Sep 11 '15 at 11:51
  • http://rextester.com/OIMF99960 – maxime.bochon Sep 11 '15 at 11:59
  • @bully No, It isnt even printing the stack trace of the Exception as well, just like I said `Exception while removing reference.` just looks like It comes from the System.out stream and not from the error stream – Einstein Sep 11 '15 at 12:27
  • @maxime.bochon of course a normal running JVM should handle the Runtime Exception but there seems to be a bug in my code itself. Thats why i added the `throw new RuntimeException();` statement. I wanted to make sure that a exception is thrown to test it. Go and look at my code and you will see that there should be a RuntimeException but it wont show up in the System Console – Einstein Sep 11 '15 at 12:30

2 Answers2

0

There are checked Exceptions and unchecked ones (everything that extends runtime exception).

The compiler force you to deal with checked exceptions (with a try catch or a throws declaration). You are not forced to deal with Unchecked exceptions. But you can, just add a try catch around your code, then you can call printstacktrace on it.

hinneLinks
  • 3,673
  • 26
  • 40
  • Do you really think wrapping a couple thousand lines of code in try catch would work? I always thought Eclipse is reminding me of checked exceptions, otherwise the code would not compile. Also that does not seem like it would crash the JVM to not respond to RuntimeExceptions anymore – Einstein Sep 11 '15 at 11:21
0

JNativeHook was blocking all console outputs. I had to enable the function first.

Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
                logger.setLevel(Level.WARNING);

did the job.

Einstein
  • 360
  • 1
  • 4
  • 15
  • What log level were you perviously set to? Do you have a stack trace that involves JNativeHook? The console output should not be blocked by default. It almost sounds like you were throwing a runtime exception for the native event callback? – Alex Barker Sep 14 '15 at 18:45