Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Division by zero exception example
// example of the throw/try/catch exception handling in C++ // try making y nonzero // try changing the exception type to int* and see what happens #include <assert.h> #include <iostream> using namespace std; int division(int a, int b) { if( b == 0 ) { throw "Division by zero condition!"; } cout << "Made it past the exception..." << endl; return (a/b); } int main () { int x = 10; int y = 0; int z; try { z = division(x, y); cout << "The answer is " << z << endl; } catch (const char* msg) { cerr << "Caught an exception! " << endl; cerr << msg << endl; } return 0; }
run
|
edit
|
history
|
help
0
11/29
Exploring stringstreams
Access namespace by unqualified manner
Throttle Example using circular queue (push all but 2 less than maxSize; then pop all but 2 less than current size)
Non type template argument
Own initialization
mpi_distributed_sort
Union-Struct-uint32_t byte order
"nearest enclosing namespace"
Composite pattern