Академический Документы
Профессиональный Документы
Культура Документы
Exception Handling
throw object;
Listing 10.2
1 template <class Type>
2 class Stack {
3 public:
4 Stack (int max);
5 ~Stack (void) {delete [] stack;}
6 void Push (Type &val);
7 void Pop (void);
8 Type& Top (void);
9 friend ostream& operator << (ostream&, Stack<Type>);
10 private:
11 Type *stack;
12 int top;
13 const int maxSize;
14 };
try {
statements
}
will match any exception type and if used, like a default case
in a switch statement, should always appear last.
The statements in a catch clause can also throw
exceptions. The case where the matched exception is to be
propagated up can be signified by an empty throw:
catch (char*) {
//...
throw; // propagate up the exception
}