/* Copyright (c) Microsoft Corporation All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. */ using System; using System.Collections.Generic; using System.Text; using System.Linq.Expressions; using System.Runtime.Serialization; using Microsoft.Research.DryadLinq.Internal; namespace Microsoft.Research.DryadLinq { /// /// The exception that is thrown by DryadLINQ. /// [Serializable] public class DryadLinqException : Exception { private int m_errorCode; /// /// Initializes an instance of DryadLinqException with a specified message. /// /// The exception message. public DryadLinqException(string message) : base(message) { } /// /// Initializes an instance of DryadLinqException with a specified message and an inner exception. /// /// The exception message. /// The inner exception. public DryadLinqException(string message, Exception inner) : base(message, inner) { } /// /// Initializes an instance of DryadLinqException with serialized data. /// /// The SerializationInfo that holds the serialized object data about the exception being thrown. /// The StreamingContext that contains contextual information about the source or destination. protected DryadLinqException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info != null) { this.m_errorCode = int.Parse(info.GetString("ErrorCode")); } } /// /// Initializes an instance of DryadLinqException with a specified error code and message. /// /// The error code. /// The exception message. internal DryadLinqException(int errorCode, string message) : base(message) { this.m_errorCode = errorCode; } /// /// Initializes an instance of DryadLinqException with a specified error code, an exception /// message, and an inner exception. /// /// The error code. /// The exception message. /// The inner exception. internal DryadLinqException(int errorCode, string message, Exception innerException) : base(message, innerException) { this.m_errorCode = errorCode; } /// /// Exception's error code. Maps to values in DryadLinqErrorCode. /// public int ErrorCode { get { return this.m_errorCode; } } /// /// Creates an instance of DryadLinqException. /// /// The error code. /// The error message. /// The current expression. /// internal static Exception Create(int errorCode, string msg, Expression expr) { StringBuilder sb = new StringBuilder(); sb.Append(msg); sb.Append(" Expression : "); sb.AppendLine(DryadLinqExpression.Summarize(expr, 1)); return new DryadLinqException(errorCode, sb.ToString()); } /// /// Sets the SerializationInfo with information about the exception. /// /// The SerializationInfo that holds the serialized object data about the exception being thrown. /// The StreamingContext that contains contextual information about the source or destination. public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); if (info != null) { info.AddValue("ErrorCode", this.m_errorCode); } } } }