Skip to content

Commit

Permalink
Updated StackOverflowError with static factory methods and obsolete c…
Browse files Browse the repository at this point in the history
…onstructors (see #446)
  • Loading branch information
NightOwl888 committed Apr 26, 2021
1 parent 55589e1 commit 88cabad
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

namespace Lucene
Expand Down Expand Up @@ -37,18 +38,22 @@ namespace Lucene
#endif
internal class StackOverflowError : Exception, IError // LUCENENET: StackOverflowException is sealed, so we subclass Exception instead and use IError to identify to Lucene.NET as an error
{
[Obsolete("Use NoClassDefFoundError.Create() instead.", error: true)]
public StackOverflowError()
{
}

[Obsolete("Use NoClassDefFoundError.Create() instead.", error: true)]
public StackOverflowError(string message) : base(message)
{
}

[Obsolete("Use NoClassDefFoundError.Create() instead.", error: true)]
public StackOverflowError(string message, Exception innerException) : base(message, innerException)
{
}

[Obsolete("Use NoClassDefFoundError.Create() instead.", error: true)]
public StackOverflowError(Exception cause) : base(cause?.ToString(), cause)
{
}
Expand All @@ -65,5 +70,19 @@ protected StackOverflowError(SerializationInfo info, StreamingContext context)
{
}
#endif

// Static factory methods

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Exception Create() => new StackOverflowException();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Exception Create(string message) => new StackOverflowException(message);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Exception Create(string message, Exception innerException) => new StackOverflowException(message, innerException);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Exception Create(Exception cause) => new StackOverflowException(cause.Message, cause);
}
}

0 comments on commit 88cabad

Please sign in to comment.