Next.js · Middle · Question 28 of 75
What happens with redirect() inside try/catch in a Server Action?
try {
await save(data);
redirect('/done');
} catch (e) {
return { error: 'Failed to save' };
}- ✓Correct answer:
catchintercepts the redirect's internal exception, so there's no redirect - 2The redirect works;
catchruns only ifsavefails - 3Next.js reports a build error
Explanation
redirect() and notFound() work by throwing special exceptions. A regular catch swallows them. The fix is to call redirect after the try/catch block or rethrow internal errors (unstable_rethrow(e)).