form Class, add a check function before the buildForm method I generate a sample Class form (and routing) with the drupal console. 

Then, I have my class with some defaults generated methods ; getFormId, buildForm...

When the user go to the url path defined in the routing file, the buildForm method is called for build the the form. 
I want call another function for check some datas before the buildForm method : 

I function like : 

function a_check_function_or_method_before_buildForm(...){
    // - Check some datas
    // - If all is ok, the buildForm can be called
    // - Else, if the custom function detect an error, the buildForm isn't called and the user is redirected to an error page
}


Is it possible to do that ? how can I do that ? 

Thank you =)
You can do all that inside of buildForm():

use Symfony\Component\HttpKernel\Exception\HttpException;

public function buildForm(array $form, FormStateInterface $form_state) {

  $data = a_check_function_or_method_before_buildForm();

  // throw an exception
  if (empty($data)) {
    throw new HttpException(500, 'No data connection.');
  }

  // or return an empty form with an error message
  if (empty($data)) {
    return $form['#markup'] = '&lt;h1&gt;No data could be collected!&lt;/h1&gt;';
  }

  // build the form with $data

}


Another possibility would be to call first a controller, which then decides what to do, return a form or something else.