HTTP ERROR 500 comes on using theme function I used following code:

Inside a route callback function.

 $my_module_form = \Drupal::formBuilder()-&gt;getForm('\Drupal\my_module\Form\MyModuleForm');
    $my_module_header_message = "hello;
    $my_module_footer_message = "hello;

 return theme('my_module',
      array(
        'my_module_header_message' =&gt; $my_module_header_message,
        'my_module_form' =&gt; $my_module_form,
        'my_module_footer_message' =&gt; $my_module_footer_message,
      )
    );


Inside my_module.module file 

/**
 * Implements hook_theme().
 */
function my_module_theme($existing, $type, $theme, $path) {
  return array(
    'my_module' =&gt; array(
      'template' =&gt; 'templates/my-module',
      'variables' =&gt; array(
        'my_module_header_message' =&gt; NULL,
        'my_module_form' =&gt; NULL,
        'my_module_footer_message' =&gt; NULL,
      ),
    ),
  );
}


I have also create templates/my-module.html.twig file and rendering hello sample content.

This is my MyModuleForm.php file

&lt;?php
/**
 * @file
 * Contains \Drupal\example\Form\MyModule.
 */

namespace Drupal\my_module\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
 * Implements an example form.
 */
class MyModuleForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'my_module_form';
  }

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

    $form['my_module_error_message'] = array(
      '#type' =&gt; 'markup',
      '#markup' =&gt; '&lt;div id="my_module_error_message"&gt; &lt;/div&gt;',
      '#weight' =&gt; 0,
    );

    return $form;
  }


  /**
   * {@inheritdoc}
   */
  public function validateForm(array &amp;$form, FormStateInterface $form_state) {

  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
  }

}


I am having problem in defining and calling hook theme for rendering drupal forms.

I think any of these 3 are wrong, a)my form definition, b) theme definition or c) theme call. 
Please tell me where am i doing wrong?
In D8 controllers return a render array. Put the template name you have defined in hook_theme() in #theme. Prefix the variable names with a '#':

return array(
      '#theme' =&gt; 'my_module',
      '#my_module_header_message' =&gt; $my_module_header_message,
      '#my_module_form' =&gt; $my_module_form,
      '#my_module_footer_message' =&gt; $my_module_footer_message,
);