| <<< | Index | >>> |
// account.h
// A banking account:
class Account { /*...*/ };
// An exception class:
struct AcctError {};
|
// main.cpp
#include <iostream>
void main() {
Account acct( 1000.00 );
try {
acct.withdraw( 2000.00 );
}
catch ( AcctError& ex ) {
std::cout << "Not enough funds";
}
}
|
// account.cpp
void Account::withdraw( double amount )
{
if ( amount > m_available_balance ) {
// Not enough balance,
// Unnamed temporary object:
throw AcctError();
}
// Balance is ok, proceed...
}
|
| <<< | Index | >>> |