| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Runtime; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Dispatcher |
| | | 8 | | { |
| | | 9 | | public abstract class ExceptionHandler |
| | | 10 | | { |
| | 0 | 11 | | public static ExceptionHandler AlwaysHandle { get; } = new AlwaysHandleExceptionHandler(); |
| | | 12 | | |
| | | 13 | | public static ExceptionHandler AsynchronousThreadExceptionHandler |
| | | 14 | | { |
| | | 15 | | get |
| | | 16 | | { |
| | 0 | 17 | | HandlerWrapper wrapper = (HandlerWrapper)Fx.AsynchronousThreadExceptionHandler; |
| | 0 | 18 | | return wrapper?.Handler; |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | set |
| | | 22 | | { |
| | 0 | 23 | | Fx.AsynchronousThreadExceptionHandler = value == null ? null : new HandlerWrapper(value); |
| | 0 | 24 | | } |
| | | 25 | | } |
| | | 26 | | |
| | 0 | 27 | | public static ExceptionHandler TransportExceptionHandler { get; set; } = AlwaysHandle; |
| | | 28 | | |
| | | 29 | | // Returns true if the exception has been handled. If it returns false or |
| | | 30 | | // throws a different exception, the original exception will be rethrown. |
| | | 31 | | public abstract bool HandleException(Exception exception); |
| | | 32 | | |
| | | 33 | | private class AlwaysHandleExceptionHandler : ExceptionHandler |
| | | 34 | | { |
| | | 35 | | public override bool HandleException(Exception exception) |
| | | 36 | | { |
| | 0 | 37 | | return true; |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | private class HandlerWrapper : Fx.ExceptionHandler |
| | | 42 | | { |
| | 0 | 43 | | public HandlerWrapper(ExceptionHandler handler) |
| | | 44 | | { |
| | | 45 | | Fx.Assert(handler != null, "Cannot wrap a null handler."); |
| | 0 | 46 | | Handler = handler; |
| | 0 | 47 | | } |
| | | 48 | | |
| | 0 | 49 | | public ExceptionHandler Handler { get; } |
| | | 50 | | |
| | | 51 | | public override bool HandleException(Exception exception) |
| | | 52 | | { |
| | 0 | 53 | | return Handler.HandleException(exception); |
| | | 54 | | } |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | } |