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
radixSort
uniq ptr
Derivation of the 0x9E3779B97F4A7C17u constant
001
hello world
general
hello world 3
Example
cv5_class
unordered graphs search