Skip to content

Commit

Permalink
Updated NoClassDefFoundError with static factory methods and obsolete…
Browse files Browse the repository at this point in the history
… constructors (see #446).
  • Loading branch information
NightOwl888 committed Apr 26, 2021
1 parent 48cdfa8 commit 55589e1
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 @@ -40,18 +41,22 @@ namespace Lucene
#endif
internal class NoClassDefFoundError : Exception, IError // LUCENENET: Subclassing Error is not allowed, so we identify with the IError interface and subclass Exception
{
[Obsolete("Use NoClassDefFoundError.Create() instead.", error: true)]
public NoClassDefFoundError()
{
}

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

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

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

// Static factory methods

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

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

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

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

0 comments on commit 55589e1

Please sign in to comment.