using System;

using CommonHelpers;

namespace LnkConverter {

class OperationFailedException: HException
{
   public OperationFailedException(string message): base( message ){}
}

static class OpFailedExceptionCreator
{
   /// <exception cref="ArgumentNullException" />
   public static OperationFailedException Create(string messageFmt,params object[] parameters)
   {
      HArgChecking.VerifyNotNulls( messageFmt, parameters );
      return new OperationFailedException( string.Format(messageFmt,parameters) );
   }
   /// <exception cref="ArgumentNullException" />
   public static OperationFailedException Create(Exception error)
   {
      HArgChecking.VerifyNotNulls( error );
      return new OperationFailedException( HException.GetErrorMessage( error ) );
   }
   /// <exception cref="ArgumentNullException" />
   /// <exception cref="OperationFailedException" />
   public static void Do(Action action)
   {
      HArgChecking.VerifyNotNull( action );
      try { action(); }
      catch (Exception e)
         { throw Create( e ); }
   }
}

static class OpFailedExceptionTranslator
{
   /// <exception cref="ArgumentNullException" />
   /// <exception cref="OperationFailedException" />
   public static void Do(Action callback)
   {
      HArgChecking.VerifyNotNull( callback );
      try
         { callback(); }
      catch (HOperationFailedException e)
         { throw OpFailedExceptionCreator.Create( e ); }
   }
}

} // LnkConverter
