You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
722 B
C++

An Example of Exception Handling
#include <iostream>
using namespace std;
int main()
{
unsigned int TypeOfLoan = 0;
const char *LoanType[] = { "Personal",
"Car",
"Furniture",
"Musical Instrument",
"Boat" };
try {
cout << "Enter the type of loan\n";
for(int i = 0; i < 4; i++)
cout << i + 1 << ") " << LoanType[i] << endl;
cout << "Your choice: ";
cin >> TypeOfLoan;
if( TypeOfLoan < 1 || TypeOfLoan > 5 )
throw "Number out of range\n";
cout << "\nType of Loan: " << LoanType[TypeOfLoan] << endl;
}
catch(const char* Msg)
{
cout << "Error: " << Msg << endl;
}
catch(...)
{
cout << "\nSomething went wrong\n\n";
}
return 0;
}