Recall: An exn can depart of the recovery job, throw another exn(exception):

try {---}
catch(someError s) {
	...
	throw SomeOtherError {};
}

or rethrow the some exn:

try {---}
catch(someError s) {
	...
	throw;
}

<aside> đź’ˇ throw; vs throw s;

IMG_3144.heic

</aside>

A handller can act as a catch-all:

try {---}    // ... : syntax of catch-all
catch(**...**) { // catches all exns
	---
}

You can throw anything you want → don’t have to throw objects

When new fails: throw std::bad alloc

Never: Let a dtor throw or propagate an exn

But - if a dtor throws during stack unwinding while dealing with another exn, you now have two active, unhandled exns, & the program will abort immediately

<aside> đź’ˇ Factory Method Pattern

Write a video game with 2 kinds of enermies: turtles + bullets

</aside>

<aside> đź’ˇ Template Method Pattern

Generalization: the Non-Virtual Interface (NVI) idiom

NVI says:

class DigitalMedia{
	public:
	virtual void play() = 0;
};
class DigitalMedia{
	public:
	void play() {
 // checkCopyright()
		doPlay();
 // updatePlayCount()
	}
	private:
	virtual void doPlay() = 0;
};

<aside> đź’ˇ Generalizes Template Method

<aside> đź’ˇ STL Maps - for creating dictionaries

eg. “arrays” that map strings to ints

import <map>
std::map<std::string, int> m;
m["abc"] = 2;
m["def"] = 3;
cout << m["ghi"]  // 0
		 << m["def"]; // 3

if key is not present, it is inserted & value is default constructed (for ints, 0)

</aside>