Skip to content

Commit

Permalink
Remove when clauses to prevent Mono crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Emik03 committed Mar 31, 2024
1 parent baf91f2 commit b4405ec
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions Source/Helper/KeyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ public static Action Catch(this Action action, Predicate<Exception> when, Action
{
action.NullCheck("The action cannot be null.")();
}
catch (Exception e) when (when(e))
catch (Exception e)
{
caught?.Invoke(e);
if (when(e))
caught?.Invoke(e);
else
throw;
}
finally
{
Expand Down Expand Up @@ -123,9 +126,11 @@ public static Action Catch<T1, T2>(this Action action, Action<Exception> caught
{
action.NullCheck("The action cannot be null.")();
}
catch (Exception e) when (e is T1 || e is T2)
catch (Exception e)
{
caught?.Invoke(e);
if (e is T1 || e is T2)
caught?.Invoke(e);
else throw;
}
finally
{
Expand Down Expand Up @@ -161,9 +166,11 @@ static Action Catch<T1, T2, T3>(this Action action, Action<Exception> caught = n
{
action.NullCheck("The action cannot be null.")();
}
catch (Exception e) when (e is T1 || e is T2 || e is T3)
catch (Exception e)
{
caught?.Invoke(e);
if (e is T1 || e is T2 || e is T3)
caught?.Invoke(e);
else throw;
}
finally
{
Expand Down Expand Up @@ -193,9 +200,11 @@ public static Action Catch<T1, T2, T3, T4>(this Action action, Action<Exception>
{
action.NullCheck("The action cannot be null.")();
}
catch (Exception e) when (e is T1 || e is T2 || e is T3 || e is T4)
catch (Exception e)
{
caught?.Invoke(e);
if (e is T1 || e is T2 || e is T3 || e is T4)
caught?.Invoke(e);
else throw;
}
finally
{
Expand All @@ -221,9 +230,12 @@ public static Func<T> Catch<T>(this Func<T> func, Predicate<Exception> when, Fun
{
return func.NullCheck("The action cannot be null.")();
}
catch (Exception e) when (when(e))
catch (Exception e)
{
return caught.NullCheck("The caught cannot be null.")(e);
if (when(e))
return caught.NullCheck("The caught cannot be null.")(e);

throw;
}
};
#endif
Expand Down Expand Up @@ -279,9 +291,12 @@ public static Func<TResult> Catch<T1, T2, TResult>(this Func<TResult> func, Func
{
return func.NullCheck("The action cannot be null.")();
}
catch (Exception e) when (e is T1 || e is T2)
catch (Exception e)
{
return caught.NullCheck("The caught cannot be null.")(e);
if (e is T1 || e is T2)
return caught.NullCheck("The caught cannot be null.")(e);

throw;
}
};
#endif
Expand Down Expand Up @@ -313,9 +328,12 @@ static Func<TResult> Catch<T1, T2, T3, TResult>(this Func<TResult> func, Func<Ex
{
return func.NullCheck("The action cannot be null.")();
}
catch (Exception e) when (e is T1 || e is T2 || e is T3)
catch (Exception e)
{
return caught.NullCheck("The caught cannot be null.")(e);
if (e is T1 || e is T2 || e is T3)
return caught.NullCheck("The caught cannot be null.")(e);

throw;
}
};

Expand All @@ -341,9 +359,12 @@ public static Func<TResult> Catch<T1, T2, T3, T4, TResult>(this Func<TResult> fu
{
return func.NullCheck("The action cannot be null.")();
}
catch (Exception e) when (e is T1 || e is T2 || e is T3 || e is T4)
catch (Exception e)
{
return caught.NullCheck("The caught cannot be null.")(e);
if (e is T1 || e is T2 || e is T3 || e is T4)
return caught.NullCheck("The caught cannot be null.")(e);

throw;
}
};

Expand Down

0 comments on commit b4405ec

Please sign in to comment.