common.dart 945 Bytes
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6 7
/// Throw a specialized exception for expected situations
/// where the tool should exit with a clear message to the user
/// and no stack trace unless the --verbose option is specified.
8
/// For example: network errors.
9
Never throwToolExit(String? message, { int? exitCode }) {
10
  throw ToolExit(message, exitCode: exitCode);
11 12
}

13 14 15
/// Specialized exception for expected situations
/// where the tool should exit with a clear message to the user
/// and no stack trace unless the --verbose option is specified.
16
/// For example: network errors.
17
class ToolExit implements Exception {
18
  ToolExit(this.message, { this.exitCode });
19

20
  final String? message;
21
  final int? exitCode;
22 23

  @override
24
  String toString() => 'Exception: $message'; // TODO(ianh): Really this should say "Error".
25
}