Gorgon
Show / Hide Table of Contents

Class GorgonExceptionExtensions

Extension methods for the Exception type.

Inheritance
object
GorgonExceptionExtensions
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Core
Assembly: Gorgon.Core.dll
Syntax
public static class GorgonExceptionExtensions

Methods

| Edit this page View Source

Catch<T>(T, Action<T>, IGorgonLog)

Function to catch and handle an exception.

Declaration
public static void Catch<T>(this T ex, Action<T> handler, IGorgonLog log = null) where T : Exception
Parameters
Type Name Description
T ex

Exception to pass to the handler.

Action<T> handler

A method that is called to handle the exception.

IGorgonLog log

[Optional] A logger that will capture the exception, or null to disable logging of this exception.

Type Parameters
Name Description
T

The type of exception. This value must be or inherit from the Exception type.

Remarks

This is a convenience method used to catch an exception and then handle it with the supplied handler method. The handler method must take a parameter that has a type that is or derives from Exception.

Exceptions
Type Condition
ArgumentNullException

Thrown when the ex parameter is null.

| Edit this page View Source

Repackage(Exception, GorgonResult)

Function to repackage an arbitrary exception as an Gorgon exception.

Declaration
public static GorgonException Repackage(this Exception ex, GorgonResult result)
Parameters
Type Name Description
Exception ex

Exception to capture and rethrow.

GorgonResult result

Result code to use.

Returns
Type Description
GorgonException

A new Gorgon exception to throw.

Remarks

The original exception will be the inner exception of the new GorgonException.

Exceptions
Type Condition
ArgumentNullException

Thrown when the ex parameter is null.

| Edit this page View Source

Repackage(Exception, GorgonResult, string)

Function to repackage an arbitrary exception as a GorgonException.

Declaration
public static GorgonException Repackage(this Exception ex, GorgonResult result, string message)
Parameters
Type Name Description
Exception ex

Exception to capture and rethrow.

GorgonResult result

Result code to use.

string message

Message to append to the result.

Returns
Type Description
GorgonException

A new Gorgon exception to throw.

Remarks

The original exception will be the inner exception of the new GorgonException.

Exceptions
Type Condition
ArgumentNullException

Thrown when the ex parameter is null.

| Edit this page View Source

Repackage(Exception, string)

Function to repackage an arbitrary exception as an Gorgon exception.

Declaration
public static GorgonException Repackage(this Exception ex, string message)
Parameters
Type Name Description
Exception ex

Exception to capture and rethrow.

string message

New message to pass to the new exception.

Returns
Type Description
GorgonException

A new Gorgon exception to throw.

Remarks

The original exception will be the inner exception of the new GorgonException.

Exceptions
Type Condition
ArgumentNullException

Thrown when the ex parameter is null.

  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author