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.
DataPortalExceptionHandler.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DataPortalExceptionHandler.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>This class provides a hoook for developers to add custom error handling in the DataPortal. </summary>
7//-----------------------------------------------------------------------
8using System;
9using Csla.Properties;
10using Csla.Reflection;
11
12namespace Csla.Server
13{
14
22 {
28 {
29 ExceptionInspector = exceptionInspector;
30 }
31
32 private IDataPortalExceptionInspector ExceptionInspector { get; set; }
33
42 public Exception InspectException(Type objectType, object criteria, string methodName, Exception ex)
43 {
44 Exception handledException;
45 if (ex is CallMethodException)
46 {
47 if (CallExceptionInspector(objectType, null, criteria, methodName, ex.InnerException, out handledException))
48 {
49 ex = new CallMethodException(methodName + " " + Resources.MethodCallFailed, handledException);
50 }
51 }
52 else
53 {
54 if (CallExceptionInspector(objectType, null, criteria, methodName, ex, out handledException))
55 {
56 ex = handledException;
57 }
58 }
59
60 return ex;
61 }
62
72 public Exception InspectException(Type objectType, object businessObject, object criteria, string methodName, Exception ex)
73 {
74 // The exception as parameter is always a CallMethodException containing the business exception as Inner exception
75 Exception handledException;
76 if (ex is CallMethodException)
77 {
78 if (CallExceptionInspector(objectType, businessObject, criteria, methodName, ex.InnerException, out handledException))
79 {
80 // developer should only transform and if rethrows a new we will wrap as new CallMethodException
81 ex = new Csla.Reflection.CallMethodException(methodName + " " + Resources.MethodCallFailed, handledException);
82 }
83 }
84 else
85 {
86 if (CallExceptionInspector(objectType, null, criteria, methodName, ex, out handledException))
87 {
88 ex = handledException;
89 }
90 }
91 return ex;
92 }
93
106 private bool CallExceptionInspector(Type objectType, object businessObject, object criteria, string methodName, Exception exception, out Exception handledException)
107 {
108 handledException = null;
109 try
110 {
111 // This method should rethrow a new exception to be handled
112 ExceptionInspector?.InspectException(objectType, businessObject, criteria, methodName, exception);
113 }
114 catch (Exception ex)
115 {
116 handledException = ex;
117 return true; // new exception returned
118 }
119 return false; // exception was not handled
120 }
121 }
122}
A strongly-typed resource class, for looking up localized strings, etc.
static string MethodCallFailed
Looks up a localized string similar to method call failed.
This exception is returned from the CallMethod method in the server-side DataPortal and contains the ...
This class provides a hook for developers to add custom error handling in the DataPortal.
DataPortalExceptionHandler(IDataPortalExceptionInspector exceptionInspector)
Creates an instance of the type.
Exception InspectException(Type objectType, object businessObject, object criteria, string methodName, Exception ex)
Transforms the exception in a Update, Delete method
Exception InspectException(Type objectType, object criteria, string methodName, Exception ex)
Transforms the exception in a Fetch, Create or Execute method.
Implement this interface to check a DataPortalException before returning Exception to the client.
void InspectException(Type objectType, object businessObject, object criteria, string methodName, Exception ex)
Inspects the exception that occurred during DataPortal call If you want to transform to/return anothe...