liveBook · Manning

Runtime error

As explained in Pro Angular 16

A runtime error is a failure that occurs while a program is executing rather than while its source is being compiled.

A runtime error occurs while JavaScript is executing, after compilation. TypeScript can catch some conditions earlier by checking declared types, but it compiles to JavaScript and does not change JavaScript’s runtime behavior. section 3.4.2

Rejecting an invalid argument at runtime

A JavaScript function adds 100 to its argument. Passing 1 produces 101, while passing "London" produces London100 unless the function checks the value. With a runtime check, the second call throws "Expected a number: London". A TypeScript number annotation moves this mismatch to compilation, where the compiler reports that string is not assignable to number. section 3.4.2

My result: 101
C:\example.js:6
        throw ("Expected a number: " + param)
        ^
Expected a number: London
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Inspect the thrown exception and Node.js output produced when the function receives an unexpected string. section 3.4.2

How Pro Angular 16 covers it

How deep it goes
Defines runtime failure through a runnable function, then stops short of broader exception-handling strategies.
Examples
Uses myFunction, numeric and string arguments, a thrown message, compiler diagnostics, and console output.
What it assumes
Assumes basic JavaScript functions and arguments while introducing TypeScript’s role in checking expected types.
What you can do after
Diagnose/debug with JavaScript console and Node.js output, then prevent selected argument mismatches with TypeScript annotations.
How it connects
Connects runtime errors with JavaScript, TypeScript, type annotations, runtime type checks, and type unions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.