예외처리 클래스
예외 처리 클래스 설계
#ifndef __ACCOUNT__
#define __ACCOUNT__
#include <iostream>
#include <string>
using namespace std;
class DepositException {
int money;
public:
DepositException(int money) : money(money) {}
void ShowException() {
cout << "[입금불가 : " << money << "]" << endl;
}
};
class WithdrawException {
int balance;
int money;
public:
WithdrawException(int money, int balance)
: money(money), balance(balance) {}
void ShowException() {
cout << "[출금불가 : " << money << ", 잔액 : " << balance << "]" << endl;
}
};
class Account {
string accNum; // 계좌번호
int balance; // 잔액
public:
Account(const char* accNum, int money)
: balance(money), accNum(accNum) {}
void Deposit(int money) {
if (money <= 0) {
DepositException exp(money); // 예외객체 생성
throw exp; // DepositException 자료형 throw
}
balance += money;
}
void Withdraw(int money) {
if (balance < money) {
throw WithdrawException(money, balance);
}
balance -= money;
}
void showInfo() {
cout << "계좌번호 : " << accNum << endl;
cout << "잔액 : " << balance << endl;
}
};
#endif예외 처리 클래스 상속
Last updated