In this code, if the if
clause is true, an exception is thrown from the CurrentAccount
constructor:
void Bank::createAccount(string accountType,int iban,int ownerid,double amount)
{
Account* toAddAccount=nullptr;
if(accountType=="CurrentAccount")
{
toAddAccount=new CurrentAccount(iban,ownerid,amount);
}
}
As you can see, the exception is not caught in this method, but is promoted higher on the stack.
I was wondering, will there be memory leak since I don't delete toAddAccount
(the CurrentAccount
constructor works with ints only)?