Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #251 from JimmyLoveSiren/master
Browse files Browse the repository at this point in the history
keep stacktrace when throws an exception
  • Loading branch information
neuecc authored Jul 16, 2018
2 parents 5eba32d + f0df3e5 commit eb99514
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 12 deletions.
15 changes: 15 additions & 0 deletions Assets/Plugins/UniRx/Scripts/InternalUtil/ExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace UniRx.InternalUtil
{
using System;

static class ExceptionExtensions
{
public static void Throw(this Exception exception)
{
#if NET_4_6
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(exception).Throw();
#endif
throw exception;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Plugins/UniRx/Scripts/InternalUtil/ListObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void OnCompleted()

public void OnError(Exception error)
{
throw error;
error.Throw();
}

public void OnNext(T value)
Expand Down
3 changes: 2 additions & 1 deletion Assets/Plugins/UniRx/Scripts/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Globalization;
using System.Collections.Generic;
using System;
using UniRx.InternalUtil;

#pragma warning disable 0659
#pragma warning disable 0661
Expand Down Expand Up @@ -270,7 +271,7 @@ public OnErrorNotification(Exception exception)
/// <summary>
/// Throws the exception.
/// </summary>
public override T Value { get { throw exception; } }
public override T Value { get { exception.Throw(); throw exception; } }

/// <summary>
/// Returns the exception.
Expand Down
9 changes: 5 additions & 4 deletions Assets/Plugins/UniRx/Scripts/Observer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading;
using UniRx.InternalUtil;

namespace UniRx
{
Expand Down Expand Up @@ -492,7 +493,7 @@ public static IDisposable SubscribeWithState3<T, TState1, TState2, TState3>(this
internal static class Stubs
{
public static readonly Action Nop = () => { };
public static readonly Action<Exception> Throw = ex => { throw ex; };
public static readonly Action<Exception> Throw = ex => { ex.Throw(); };

// marker for CatchIgnore and Catch avoid iOS AOT problem.
public static IObservable<TSource> CatchIgnore<TSource>(Exception ex)
Expand All @@ -505,19 +506,19 @@ internal static class Stubs<T>
{
public static readonly Action<T> Ignore = (T t) => { };
public static readonly Func<T, T> Identity = (T t) => t;
public static readonly Action<Exception, T> Throw = (ex, _) => { throw ex; };
public static readonly Action<Exception, T> Throw = (ex, _) => { ex.Throw(); };
}

internal static class Stubs<T1, T2>
{
public static readonly Action<T1, T2> Ignore = (x, y) => { };
public static readonly Action<Exception, T1, T2> Throw = (ex, _, __) => { throw ex; };
public static readonly Action<Exception, T1, T2> Throw = (ex, _, __) => { ex.Throw(); };
}


internal static class Stubs<T1, T2, T3>
{
public static readonly Action<T1, T2, T3> Ignore = (x, y, z) => { };
public static readonly Action<Exception, T1, T2, T3> Throw = (ex, _, __, ___) => { throw ex; };
public static readonly Action<Exception, T1, T2, T3> Throw = (ex, _, __, ___) => { ex.Throw(); };
}
}
3 changes: 2 additions & 1 deletion Assets/Plugins/UniRx/Scripts/Operators/Wait.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using UniRx.InternalUtil;

namespace UniRx.Operators
{
Expand Down Expand Up @@ -36,7 +37,7 @@ public T Run()
}
}

if (ex != null) throw ex;
if (ex != null) ex.Throw();
if (!seenValue) throw new InvalidOperationException("No Elements.");

return value;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Plugins/UniRx/Scripts/Subjects/AsyncSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public T Value
{
ThrowIfDisposed();
if (!isStopped) throw new InvalidOperationException("AsyncSubject is not completed yet");
if (lastError != null) throw lastError;
if (lastError != null) lastError.Throw();
return lastValue;
}
}
Expand Down Expand Up @@ -315,7 +315,7 @@ public T GetResult()

if (lastError != null)
{
throw lastError;
lastError.Throw();
}

if (!hasValue)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Plugins/UniRx/Scripts/Subjects/BehaviorSubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public T Value
get
{
ThrowIfDisposed();
if (lastError != null) throw lastError;
if (lastError != null) lastError.Throw();
return lastValue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UniRx.InternalUtil;
using UniRx.Triggers;
using UnityEngine;
using System.Threading;
Expand Down Expand Up @@ -151,7 +152,7 @@ bool IEnumerator.MoveNext()
{
if (reThrowOnError && HasError)
{
throw Error;
Error.Throw();
}

return false;
Expand Down Expand Up @@ -1143,7 +1144,7 @@ static IEnumerable<IObservable<T>> RepeatInfinite<T>(IObservable<T> source)
internal static class Stubs
{
public static readonly Action Nop = () => { };
public static readonly Action<Exception> Throw = ex => { throw ex; };
public static readonly Action<Exception> Throw = ex => { ex.Throw(); };

// Stubs<T>.Ignore can't avoid iOS AOT problem.
public static void Ignore<T>(T t)
Expand Down
3 changes: 3 additions & 0 deletions Dlls/UniRx.Library/UniRx.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
<Compile Include="..\..\Assets\Plugins\UniRx\Scripts\InternalUtil\AscynLock.cs">
<Link>InternalUtil\AscynLock.cs</Link>
</Compile>
<Compile Include="..\..\Assets\Plugins\UniRx\Scripts\InternalUtil\ExceptionExtensions.cs">
<Link>ExceptionExtensions.cs</Link>
</Compile>
<Compile Include="..\..\Assets\Plugins\UniRx\Scripts\InternalUtil\ImmutableList.cs">
<Link>InternalUtil\ImmutableList.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions Dlls/UniRx/UniRx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@
<Compile Include="..\..\Assets\Plugins\UniRx\Scripts\InternalUtil\AscynLock.cs">
<Link>InternalUtil\AscynLock.cs</Link>
</Compile>
<Compile Include="..\..\Assets\Plugins\UniRx\Scripts\InternalUtil\ExceptionExtensions.cs">
<Link>ExceptionExtensions.cs</Link>
</Compile>
<Compile Include="..\..\Assets\Plugins\UniRx\Scripts\InternalUtil\ImmutableList.cs">
<Link>InternalUtil\ImmutableList.cs</Link>
</Compile>
Expand Down

0 comments on commit eb99514

Please sign in to comment.