Table of Contents

Class DelegateHelpers

Namespace
Garyon.Functions
Assembly
Garyon.dll
public static class DelegateHelpers
Inheritance
DelegateHelpers
Inherited Members

Methods

Try(Action)

Tries the execution of a delegate and ignores any exceptions that may occur. Returns true if the delegate was executed successfully, otherwise false if an exception was thrown.

public static bool Try(Action action)

Parameters

action Action

Returns

bool

Try<T>(Func<T>, T?)

Invokes the specified function and returns its result, or a default value if an exception is thrown.

public static T? Try<T>(Func<T> func, T? defaultValue = default)

Parameters

func Func<T>

The function to invoke. Cannot be null.

defaultValue T

The value to return if the function throws an exception. The default value for type T is used if not specified.

Returns

T

The result of the function if it completes successfully; otherwise, the specified default value.

Type Parameters

T

The type of the value returned by the function.

Remarks

This method catches all exceptions thrown by the function and returns the default value instead. Use with caution, as it may suppress unexpected errors.