CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
DataPortalException.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DataPortalException.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>This exception is returned for any errors occuring</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Security.Permissions;
11
12namespace Csla
13{
18 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")]
20 public class DataPortalException : Exception
21 {
28 public DataPortalException(string message, object businessObject)
29 : base(message)
30 {
31 _innerStackTrace = String.Empty;
32 _businessObject = businessObject;
33 }
34
42 public DataPortalException(string message, Exception ex, object businessObject)
43 : base(message, ex)
44 {
45 _innerStackTrace = ex.StackTrace;
46 _businessObject = businessObject;
47 }
48
58 public DataPortalException(string message, Exception ex)
59 : base(message, ex)
60 {
61 _innerStackTrace = ex.StackTrace;
62 }
63
69 : base(info.Message)
70 {
71 this.ErrorInfo = info;
72 }
73
78 public override string ToString()
79 {
80 var sb = new System.Text.StringBuilder();
81 sb.AppendLine(base.ToString());
82 if (ErrorInfo != null)
83 {
84 sb.AppendLine("------------------------------");
85 var error = this.ErrorInfo;
86 while (error != null)
87 {
88 sb.AppendFormat("{0}: {1}", error.ExceptionTypeName, error.Message);
89 sb.Append(Environment.NewLine);
90 sb.Append(error.StackTrace);
91 sb.Append(Environment.NewLine);
92 error = error.InnerError;
93 }
94 }
95 return sb.ToString();
96 }
97
105 public DataPortalErrorInfo ErrorInfo { get; private set; }
106
112 {
113 get
114 {
115 var result = ErrorInfo;
116 while (result.InnerError != null)
117 result = result.InnerError;
118 return result;
119 }
120 }
121
122 private object _businessObject;
123 private string _innerStackTrace;
124
137 public object BusinessObject
138 {
139 get { return _businessObject; }
140 }
141
142 private Exception _businessException;
143
153 public Exception BusinessException
154 {
155 get
156 {
157 if (_businessException == null)
158 {
159 _businessException = this.InnerException;
160 while (_businessException is Csla.Reflection.CallMethodException || _businessException is DataPortalException)
161 _businessException = _businessException.InnerException;
162 }
163 return _businessException;
164 }
165 }
166
174 {
175 get
176 {
177 if (ErrorInfo != null)
179 else if (BusinessException == null)
180 return Message;
181 else
182 return BusinessException.Message;
183 }
184 }
185
190 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.String.Format(System.String,System.Object,System.Object,System.Object)")]
191 public override string StackTrace
192 {
193 get { return String.Format("{0}{1}{2}", _innerStackTrace, Environment.NewLine, base.StackTrace); }
194 }
195
201 protected DataPortalException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
202 : base(info, context)
203 {
204 _businessObject = info.GetValue("_businessObject", typeof(object));
205 _innerStackTrace = info.GetString("_innerStackTrace");
206 }
207
213 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
214#if !NET5_0 && !NET6_0
215 [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
216 [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)]
217#endif
218 public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
219 {
220 base.GetObjectData(info, context);
221 info.AddValue("_businessObject", _businessObject);
222 info.AddValue("_innerStackTrace", _innerStackTrace);
223 }
224 }
225}
This exception is returned for any errors occurring during the server-side DataPortal invocation.
override string ToString()
Gets a string representation of this object.
override string StackTrace
Get the combined stack trace from the server and client.
DataPortalException(DataPortalErrorInfo info)
Creates an instance of the type.
object BusinessObject
Returns a reference to the business object from the server-side DataPortal.
string BusinessExceptionMessage
Gets the Message property from the BusinessException, falling back to the Message value from the top-...
DataPortalErrorInfo BusinessErrorInfo
Gets the original exception error info that caused this exception.
override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
Serializes the object.
DataPortalErrorInfo ErrorInfo
Gets information about the original server-side exception.
DataPortalException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
Creates an instance of the object for serialization.
DataPortalException(string message, Exception ex, object businessObject)
Creates an instance of the type.
Exception BusinessException
Gets the original server-side exception.
DataPortalException(string message, Exception ex)
Creates an instance of the type.
DataPortalException(string message, object businessObject)
Creates an instance of the type.
override string ToString()
Returns a text representation of this object by returning the GetIdValue value in text form.
Definition: ReadOnlyBase.cs:76
This exception is returned from the CallMethod method in the server-side DataPortal and contains the ...
Message containing details about any server-side exception.
string Message
Message from the exception object.
DataPortalErrorInfo InnerError
HttpErrorInfo object containing information about any inner exception of the original exception.
@ Serializable
Prevents updating or inserting until the transaction is complete.