Formatting problem with catch block

Problem description:

In this Java code, the try { } block is properly indented, the catch { } block is not indented, it lines up with the catch block

Expected behavior:
Consistent indentation in try and catch blocks
Actual behavior:
See below - the catch block code lines up with the keyword, it should be indented

Steps to reproduce:

Wrote this code. I’d be interested to hear if anyone else has the same problem, or is it just my repl. [It’s in a Teams for Education repl, so I can’t post a public link, sorry.]

public static void demoTryCatch() {
    final double ADULT_FARE = 25.00;
    final double REDUCED_FARE = 15.00;
    try {
      Scanner scan = new Scanner(;
      System.out.print("Enter your age: ");
      int age = scan.nextInt();
      double fare = (age >= 18 && age <= 65) ? ADULT_FARE : REDUCED_FARE;
    } catch (InputMismatchException ime) {
      System.out.printf("Please enter a whole number (%s)\n", ime.getMessage());
    System.out.println("And the program keeps going ...\u263A");


Bug appears at this link:


i like it, because its more compact
Maybe there should be a setting to change whether or not things like this should be inline or not

The indentation in the code snippet you provided looks correct. What happens when you set the indentation size to four spaces?

1 Like

Nice call – I had it at 2 spaces, and gave me what I pasted. At 4, it works. Weird.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.