//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;

#if !WASM
namespace CommonHelpers {
#else
namespace CommonHelpers.WASM {
#endif

//**************************************************************************************************
/// <summary>
/// </summary>
public static partial class HUnsuccessExceptionCreator {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="ArgumentNullException" />
public static HUnsuccessException Create(string messageFmt,params object[] parameters)
{
   HArgChecking.VerifyNotNulls( messageFmt, parameters );
   return new HUnsuccessException(string.Format( messageFmt, parameters ));
}

/// <exception cref="ArgumentNullException" />
public static HUnsuccessException Create(Exception error)
{
   HArgChecking.VerifyNotNulls( error );
   return new HUnsuccessException( HException.GetErrorMessage( error ) );
}

//==================================================================================================

/// <exception cref="ArgumentNullException" />
/// <exception cref="HUnsuccessException" />
public static void Do(Action action)
{
   HArgChecking.VerifyNotNull( action );
   try { action(); }
   catch (Exception e)
      { throw Create( e ); }
}

/// <exception cref="ArgumentNullException" />
/// <exception cref="HUnsuccessException" />
public static T Do<T>(Func<T> function)
{
   HArgChecking.VerifyNotNull( function );
   try { return function(); }
   catch (Exception e)
      { throw Create( e ); }
}

//==================================================================================================

static HUnsuccessExceptionCreator()
{
   CommonHelpers_Core.Access();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HUnsuccessExceptionCreator
//**************************************************************************************************

} // CommonHelpers (.WASM)
