exception.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //===- exception.h ----------------------------------------------*- C++ -*-===//
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // exception.h //
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. // This file is distributed under the University of Illinois Open Source //
  7. // License. See LICENSE.TXT for details. //
  8. // //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #pragma once
  11. #include "dxc/Support/ErrorCodes.h"
  12. #include <exception>
  13. #include <string>
  14. namespace hlsl
  15. {
  16. /// <summary>
  17. /// Exception stores off information about an error and its error message for
  18. /// later consumption by the hlsl compiler tools.
  19. /// </summary>
  20. struct Exception : public std::exception
  21. {
  22. /// <summary>HRESULT error code. Must be a failure.</summary>
  23. HRESULT hr;
  24. std::string msg;
  25. Exception(HRESULT errCode) : hr(errCode) { }
  26. Exception(HRESULT errCode, const std::string &errMsg) : hr(errCode), msg(errMsg) { }
  27. // what returns a formatted message with the error code and the message used
  28. // to create the message.
  29. virtual const char *what() const throw() { return msg.c_str(); }
  30. };
  31. } // namespace hlsl