0

i am doing a work and i am stuck here:

my code is :

public void AddTransaction(ITransaction transaction)
    {

            if (((transaction is WithdrawalTransaction) || transaction is FundsTransferTransaction) && GetBalance() < transaction.Amount)
            {
                throw new DebitException(transaction.Amount);
            }
            else if ((transaction is WithdrawalTransaction) && (transaction.Amount < -350))
            {
                throw new DebitException(transaction.Amount);

            }
            else
            {
                transactions.Add(transaction.TransactionID, transaction);

            }

    } 

and i am supposed to give it an error box that if the transaction is more than 350 an error message should appear.

please help

CRD
  • 52,522
  • 5
  • 70
  • 86
  • you want to throw the exception when minimum balance is less than 350? – Sudhakar Tillapudi Nov 23 '13 at 04:08
  • @user3024043 exceptions should ideally be thrown for situations that are exceptional (e.g. Out of memory). They are quite expensive. You also are sitting on a Timebomb with all those if statements. Have you seen a state machine before http://www.dreamincode.net/forums/topic/225251-implementing-state-pattern-problem/ – Sico Nov 23 '13 at 04:11
  • 1
    @Sico The day Exceptions will be the real bottleneck of any application, call me, I want to see this. Unless you're on a C64, it shouldn't matter one bit. – Pierre-Luc Pineault Nov 23 '13 at 04:13
  • Ok take back the expensive bit if you want, but think the OP should at least be following exceptions when exceptional http://stackoverflow.com/questions/77127/when-to-throw-an-exception – Sico Nov 23 '13 at 04:21

1 Answers1

0

not sure if this is what you are trying to do?

 if (transaction.Amount > 350
{
throw new ApplicationException("My Error message");
}

OR

if (transaction.Amount > 350)
{
MessageBox.Show("It is more than 350");
 }

This is not how you should handle this situation idealy.

rune711
  • 351
  • 1
  • 11
  • @Sudhakar I am making a project so when i want to withdraw any amount more than -350 i should get an error and it should not execute. – user3024043 Nov 24 '13 at 19:06