How to intercept not found URL, parse it, and generate dynamic result?

How to intercept not found URL, parse it, and generate dynamic result?