docs/docs/en/runjs/context/exit.md
Stops the current event flow; later steps in that flow do not run. Often used when business conditions fail, the user cancels, or an unrecoverable error occurs.
ctx.exit() is used in contexts that execute JS, such as:
| Scenario | Description |
|---|---|
| Event flow | In flows triggered by form submit, button click, etc., stop when conditions are not met |
| Linkage rules | Field or filter linkage; stop when validation fails or execution should be skipped |
| Action events | In custom actions (e.g. delete confirm, pre-save validation), exit when user cancels or validation fails |
Difference from
ctx.exitAll():ctx.exit()only stops the current event flow; other flows for the same event still run.ctx.exitAll()also stops subsequent flows for that event.
exit(): never;
Calling ctx.exit() throws an internal FlowExitException, which the event flow engine catches and uses to stop the current flow. Once called, the rest of the current JS does not run.
| Method | Scope |
|---|---|
ctx.exit() | Stops only the current event flow; others unaffected |
ctx.exitAll() | Stops the current flow and subsequent flows for the same event |
if (!confirmed) {
ctx.message.info('Cancelled');
ctx.exit();
}
if (!params.value || params.value.length < 3) {
ctx.message.error('Invalid: length must be at least 3');
ctx.exit();
}
const record = ctx.model?.getValue?.();
if (!record || record.status !== 'draft') {
ctx.notification.warning({ message: 'Only draft can be submitted' });
ctx.exit();
}
// Only this flow should stop → ctx.exit()
if (!params.valid) {
ctx.message.error('Invalid params');
ctx.exit();
}
// Stop this and all subsequent flows for this event → ctx.exitAll()
if (!ctx.model?.context?.getPermission?.()) {
ctx.notification.warning({ message: 'No permission' });
ctx.exitAll();
}
const ok = await ctx.modal?.confirm?.({
title: 'Confirm delete',
content: 'Cannot be recovered. Continue?',
});
if (!ok) {
ctx.message.info('Cancelled');
ctx.exit();
}
ctx.exit(), the rest of the current JS does not run; use ctx.message, ctx.notification, or a dialog before calling to explain why.FlowExitException; the event flow engine handles it.ctx.exitAll().