2

I'm learning Java. Yesterday I've created a project, I was compiling and running and it was showing full stack trace on exceptions. Something like this:

java.util.NoSuchElementException: No line found     
   at java.util.Scanner.nextLine(Unknown Source)    
   at myprog1.MyProg1.main(MyProg1.java:22)

Today maybe I have done something and it doesn't show any stack trace anymore. Only one of the two types of output are showing:

java -XX:-OmitStackTraceInFastThrow -jar myprog1.jar

Exception in thread "main" java.util.NoSuchElementException: No line found

and

java -XX:-OmitStackTraceInFastThrow -jar myprog1.jar

Exception in thread "main"

I'm compiling with flag "-g" in NetBeans IDE. The code is very simple:

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String str = scanner.nextLine();
}

and I use Ctrl-C to generate the exception.

happy_marmoset
  • 2,137
  • 3
  • 20
  • 25

1 Answers1

0

The flag you placed -XX:-OmitStackTraceInFastThrow is the cause. This allows java to reuse certain exceptions in order to speed up exceptions, however, it will lead to stack traces being hidden. Simply removing the flag should let you see the stack traces again.

java -jar myprog1.jar

Also, CTRL+C does not generate an exception per se. What CTRL+C does is interrupt your program, and throws an exception if scanner.nextLine(); is currently running, so keep that in mind.