files/en-us/web/api/gpudevice/pusherrorscope/index.md
{{APIRef("WebGPU API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The pushErrorScope() method of the
{{domxref("GPUDevice")}} interface pushes a new GPU error scope onto the device's error scope stack, allowing you to capture errors of a particular type.
Once you are done capturing errors, you can end capture by invoking {{domxref("GPUDevice.popErrorScope()")}}. This pops the scope from the stack and returns a {{jsxref("Promise")}} that resolves to an object describing the first error captured in the scope, or null if no errors were captured.
pushErrorScope(filter)
filter
"internal"
"out-of-memory"
"validation"
None ({{jsxref("Undefined")}}).
The following example uses an error scope to capture a suspected validation error, logging it to the console.
device.pushErrorScope("validation");
let sampler = device.createSampler({
maxAnisotropy: 0, // Invalid, maxAnisotropy must be at least 1.
});
device.popErrorScope().then((error) => {
if (error) {
sampler = null;
console.error(`An error occurred while creating sampler: ${error.message}`);
}
});
See WebGPU Error Handling best practices for a lot more examples and information.
{{Specifications}}
{{Compat}}