Redirect on invalid URLS

I understand this to enable and disable routes/pages. But how can i redirect a user to a specific page if they fail.

going to an account with an id that doesnt exist redirect them to listing page with a toast message saying account does not exist etc.

What code did you write?