[Yandex Cloud documentation](../../../index.md) > [Yandex Cloud Functions](../../index.md) > [Developing in Node.js](index.md) > Error handling

# Node.js function error handling

If a [handler](handler.md) reports a Node.js function execution or loading error, the [runtime](../../concepts/runtime/index.md) automatically catches the error and returns a JSON document with details of the error type, text, and location. For more information about the JSON document format, see [Invoking a function](../../concepts/function-invoke.md#error).

The error info is also written to the [execution log](logging.md). You can [view](../../operations/function/function-logs.md) the log via the [Yandex Cloud CLI](../../../cli/index.md) or the [management console](https://console.yandex.cloud).

#### Example of error handling {#example}

Function code:

```js
module.exports.handler = function () {
    return unknownVariable;
};
```

JSON document returned:

```json
{
  "errorMessage": "unknownVariable is not defined",
  "errorType": "ReferenceError",
  "stackTrace": [
    ...
  ]
}
```