Skip to content

MVC Code generation fails to declare exception when constructor throws a checked exception #3737

@candcdev

Description

@candcdev

Using Jooby 4.0.1
create myapp7 --mvc --server undertow --gradle

and change the constructor of the Controller to make it throw an Exception

package app;

import io.jooby.annotation.*;

@Path("/")
public class Controller {

  public Controller() **throws  Exception{**

  }

  @GET
  public String sayHi() {
    return "Welcome to Jooby!";
  }
}

but the generated class fails to compile:

@io.jooby.annotation.Generated(Controller.class)
public class Controller_ implements io.jooby.Extension {
    protected java.util.function.Function<io.jooby.Context, Controller> factory;

    public Controller_() {
      this(new Controller()); // error: unreported exception Exception; must be caught or declared to be thrown 

    }

    ... 
}

error: unreported exception Exception; must be caught or declared to be thrown this(new Controller());

In our framework we are using parent controllers who's constructors throw checked exceptions and we cannot change this.

public class Controller extends SomeOtherController{ 
 public Controller() **throws  Exception{**
   super(); //this throws
  }

Is this a known feature, limitation, incorrect usage, bug or is some other approach is required?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions