Our site has a custom error page for 404 responses. The page title on that page says "404 - Page Not Found". I use driver.Title and check for the text "not found".
Using C#, I wrote the following:
// Check for 404 page:
var pageNotFoundTitleText = "not found";
if (driver.Title.ToLower().Contains(pageNotFoundTitleText)) throw new Exception("### 404 - Page Not found: " + link);