exception.h 1.5 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 "dxc/Support/WinAdapter.h"
  13. #include <exception>
  14. #include <string>
  15. namespace hlsl
  16. {
  17. /// <summary>
  18. /// Exception stores off information about an error and its error message for
  19. /// later consumption by the hlsl compiler tools.
  20. /// </summary>
  21. struct Exception : public std::exception
  22. {
  23. /// <summary>HRESULT error code. Must be a failure.</summary>
  24. HRESULT hr;
  25. std::string msg;
  26. Exception(HRESULT errCode) : hr(errCode) { }
  27. Exception(HRESULT errCode, const std::string &errMsg) : hr(errCode), msg(errMsg) { }
  28. // what returns a formatted message with the error code and the message used
  29. // to create the message.
  30. virtual const char *what() const throw() { return msg.c_str(); }
  31. };
  32. } // namespace hlsl