title: ExpressJS error handling doesn't work
body: <p>At the very end of my server.js file I have the following code:</p>
  
  <pre><code>app.use(logErrors);
  
  function logErrors (err: Error, req: Request, res: Response, next: NextFunction) {
      console.log(err);
      mongoDal.log(err.message, err);
      next(err);
  }
  </code></pre>
  
  <p>but this code doesn't get reached when an error occurs.</p>
  
  <p>I also have the Node.js error handling function, which doesn't get reached either:</p>
  
  <pre><code>process.on('uncaughtException', function (err: Error) {
      try {
          console.log(err);
          mongoDal.log(err.message, err);
      } catch (err) {
  
      }
  });
  </code></pre>
  
  <p>This is the code that produces the error:</p>
  
  <pre><code>app.get('/test_feature', function (req: Request, res: Response) {
      makeError();
  
      res.send("Done");
  });
  
  function makeError(){
      throw new Error("asdasdad");
  }
  </code></pre>
  
  <p>BTW the error does get written into the console (but not by a function of mine), and the app doesn't crash.</p>
  
  <p>What I'm trying to make is a generic solution that will catch every unhandled exception in one place.</p>
  
  <p>What am I doing wrong?</p>