Skip to content
This repository was archived by the owner on Mar 31, 2018. It is now read-only.
This repository was archived by the owner on Mar 31, 2018. It is now read-only.

Examples of synchronous operational errors #23

@benjamingr

Description

@benjamingr

I'd like to collect some examples of operational errors in Node that are synchronously thrown at the moment.

Please post examples you're aware of

Examples:

  1. Out of memory
  2. Parsing invalid JSON
  3. Attempting to bind to a closed UDP socket.
  4. Listening to an invalid port

Out of memory

const arr = []; // example and case by trevnorris
  while (true)
    arr.push(new Buffer(0xfffffff).fill(0));  // alloc until OOM, throws synchronously

Parsing Invalid JSON

var j = JSON.parse("{'hello': 5}"); // throws synchronously

Attempting to bind to a closed UDP socket

From https://nodejs.org/api/dgram.html

If binding fails, an 'error' event is generated. In rare case (e.g. attempting to bind with a closed socket), an Error may be thrown.

Listening to an invalid port

https://github.com/nodejs/node/blob/master/lib/net.js#L1340


Of course, every single *Sync method in the API throws synchronously, although in theory they could take callbacks and execute them with err synchronously. This includes calls to require for example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions