1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. 2 3 using System.ComponentModel; 4 using System.Reactive.PlatformServices; 5 6 namespace System.Reactive 7 { 8 internal static class ExceptionHelpers 9 { 10 private static Lazy<IExceptionServices> s_services = new Lazy<IExceptionServices>(Initialize); 11 Throw(this Exception exception)12 public static void Throw(this Exception exception) 13 { 14 s_services.Value.Rethrow(exception); 15 } 16 ThrowIfNotNull(this Exception exception)17 public static void ThrowIfNotNull(this Exception exception) 18 { 19 if (exception != null) 20 s_services.Value.Rethrow(exception); 21 } 22 Initialize()23 private static IExceptionServices Initialize() 24 { 25 return PlatformEnlightenmentProvider.Current.GetService<IExceptionServices>() ?? new DefaultExceptionServices(); 26 } 27 } 28 } 29 30 namespace System.Reactive.PlatformServices 31 { 32 /// <summary> 33 /// (Infrastructure) Services to rethrow exceptions. 34 /// </summary> 35 /// <remarks> 36 /// This type is used by the Rx infrastructure and not meant for public consumption or implementation. 37 /// No guarantees are made about forward compatibility of the type's functionality and its usage. 38 /// </remarks> 39 [EditorBrowsable(EditorBrowsableState.Never)] 40 public interface IExceptionServices 41 { 42 /// <summary> 43 /// Rethrows the specified exception. 44 /// </summary> 45 /// <param name="exception">Exception to rethrow.</param> Rethrow(Exception exception)46 void Rethrow(Exception exception); 47 } 48 } 49