C++ CoP 👷🏼♂️👷🏼♀️
Integer Types
#include <limits> // holds constants for int size, e.g. INT_MAX, INT_MIN, etc..
sizes (dependent on compiler used)
short int - 16 bits int - 32 bits long int - 64 bits
sizeof(int)
returns number of bytes used
Some compilers allow long
instead of long int
, the same also applies to short
in place of short int
Exceptions
CoP Thought: Only use them for states from which your can't recover from. (e.g. unable to allocate enough memory) (Or alternatively - use for all error handling and keep error handling separate from main code)
void mightGoWrong() {
bool error = true;
if(error) throw 8;
}
asd
int main() {
try {
mightGoWrong();
} catch(int e) {
cout << "Error code: " << e << endl;
} catch(std::string & e) {
cout << "Error message: " << e << endl;
} catch(char const * e) {
cout << "Error message: " << e << endl;
}
}
Can throw anything as an exception - including primitives, error strings and objects. (however you do need to catch the correct type)