Throw

Here’s an example of throwing, or raising, an exception:

  1. throw FormatException('Expected at least 1 section');

You can also throw arbitrary objects:

  1. throw 'Out of llamas!';

Note: Production-quality code usually throws types that implement Error or Exception.

Because throwing an exception is an expression, you can throw exceptionsin => statements, as well as anywhere else that allows expressions:

  1. void distanceTo(Point other) => throw UnimplementedError();