Consider this Next.js server action that throws an error. What will the client receive?
export async function action() { try { throw new Error('Failed to save data') } catch (error) { return { success: false, message: error.message } } }
Look at what the catch block returns.
The catch block returns a JSON object with success false and the error message. This is sent to the client.
If a server component throws an error during rendering, what happens?
export default function ServerComponent() { throw new Error('Render failed') return <div>Should not render</div> }
Think about Next.js default error handling behavior in dev and prod.
Next.js shows a red error overlay in development for thrown errors and a 500 error page in production.
Examine this API route code. Why does the client get a 500 error with no JSON?
export default function handler(req, res) { try { throw new Error('Oops') } catch { res.status(500).json({ error: 'Server error' }) return; } res.json({ success: true }) }
Look at the flow after the catch block.
The res.json is called twice: once in catch and once after, causing an error and no JSON sent.
Choose the code that correctly throws a custom error with a message and status code.
Remember how to add custom properties to Error objects.
Only option B creates an Error object, adds a status property, and throws it correctly.
Given this server action, what is the value of errorMessage after execution?
let errorMessage = '' export async function action() { try { await Promise.reject(new Error('Failed to fetch')) } catch (error) { errorMessage = error.message } return errorMessage }
Check how the catch block sets errorMessage.
The rejected promise triggers the catch block which sets errorMessage to the error's message.