Let's explore how to add the path of a non-existent page as a query string parameter to a 404 page. This site's _redirects file is as follows:

/:language/invalid path=:path /:language/404 404
/:language/* /:language/invalid?path=/:language/:splat 301


Navigating to /en/doh redirects to /en/invalid?path=/en/doh which is configured to shadow the /en/404 page.

The order of the rules is important, in order to avoid a redirect loop.

This could be easily amended to shadow a generic /404 page.