RpcException.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #region Copyright notice and license
  2. // Copyright 2015 gRPC authors.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System;
  17. using Grpc.Core.Utils;
  18. namespace Grpc.Core
  19. {
  20. /// <summary>
  21. /// Thrown when remote procedure call fails. Every <c>RpcException</c> is associated with a resulting <see cref="Status"/> of the call.
  22. /// </summary>
  23. public class RpcException : Exception
  24. {
  25. private readonly Status status;
  26. private readonly Metadata trailers;
  27. /// <summary>
  28. /// Creates a new <c>RpcException</c> associated with given status.
  29. /// </summary>
  30. /// <param name="status">Resulting status of a call.</param>
  31. public RpcException(Status status) : base(status.ToString())
  32. {
  33. this.status = status;
  34. this.trailers = Metadata.Empty;
  35. }
  36. /// <summary>
  37. /// Creates a new <c>RpcException</c> associated with given status and message.
  38. /// </summary>
  39. /// <param name="status">Resulting status of a call.</param>
  40. /// <param name="message">The exception message.</param>
  41. public RpcException(Status status, string message) : base(message)
  42. {
  43. this.status = status;
  44. this.trailers = Metadata.Empty;
  45. }
  46. /// <summary>
  47. /// Creates a new <c>RpcException</c> associated with given status and trailing response metadata.
  48. /// </summary>
  49. /// <param name="status">Resulting status of a call.</param>
  50. /// <param name="trailers">Response trailing metadata.</param>
  51. public RpcException(Status status, Metadata trailers) : base(status.ToString())
  52. {
  53. this.status = status;
  54. this.trailers = GrpcPreconditions.CheckNotNull(trailers);
  55. }
  56. /// <summary>
  57. /// Resulting status of the call.
  58. /// </summary>
  59. public Status Status
  60. {
  61. get
  62. {
  63. return status;
  64. }
  65. }
  66. /// <summary>
  67. /// Gets the call trailing metadata.
  68. /// Trailers only have meaningful content for client-side calls (in which case they represent the trailing metadata sent by the server when closing the call).
  69. /// Instances of <c>RpcException</c> thrown by the server-side part of the stack will have trailers always set to empty.
  70. /// </summary>
  71. public Metadata Trailers
  72. {
  73. get
  74. {
  75. return trailers;
  76. }
  77. }
  78. }
  79. }