error.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef EXECUTABLE_SEMANTICS_COMMON_ERROR_H_
  5. #define EXECUTABLE_SEMANTICS_COMMON_ERROR_H_
  6. #include "common/check.h"
  7. namespace Carbon {
  8. // Prints an error and exits. This should be used for non-recoverable errors
  9. // with user input.
  10. //
  11. // For example:
  12. // FATAL_PROGRAM_ERROR(line_num) << "Line is bad!";
  13. // FATAL_PROGRAM_ERROR_NO_LINE() << "Application is bad!";
  14. //
  15. // Where possible, try to identify the error as a compilation or
  16. // runtime error. Use CHECK/FATAL for internal errors. The generic program error
  17. // option is provided as a fallback for cases that don't fit those
  18. // classifications.
  19. #define FATAL_PROGRAM_ERROR_NO_LINE() \
  20. Carbon::ExitingStream() << "PROGRAM ERROR: "
  21. #define FATAL_PROGRAM_ERROR(line) FATAL_PROGRAM_ERROR_NO_LINE() << line << ": "
  22. #define FATAL_COMPILATION_ERROR_NO_LINE() \
  23. Carbon::ExitingStream() << "COMPILATION ERROR: "
  24. #define FATAL_COMPILATION_ERROR(line) \
  25. FATAL_COMPILATION_ERROR_NO_LINE() << line << ": "
  26. #define FATAL_RUNTIME_ERROR_NO_LINE() \
  27. Carbon::ExitingStream() << "RUNTIME ERROR: "
  28. #define FATAL_RUNTIME_ERROR(line) FATAL_RUNTIME_ERROR_NO_LINE() << line << ": "
  29. } // namespace Carbon
  30. #endif // EXECUTABLE_SEMANTICS_COMMON_ERROR_H_