What is the best practice to show an 404 page if a record is not found

When I create an own extension that is using its own records and try to display a details page for a deleted or non existing record there is an TargetNotFoundException. What is the best / suggested way to display the default 404 page in this case?