According to Google's ad placement policies:
Ads on thank you, exit, log in, or error pages
Publishers are not permitted to place ads on any non-content based pages like thank you, error, log in, or exit pages. These are pages that visitors see on a site before potentially leaving the domain or after performing a specific action on the site such as a purchase or download.

Ads that are the main focus on these types of pages can confuse a visitor into thinking that the ads are actual content, so do not place ads on such pages.
This will be a challenge for adding AdSense in a text widget because the ads will show up in a 404 error page, which is against the policies.