try {
throw 10; //Error Detected and "Thrown" to catch block
}
catch (char *excp) { //if error is thrown matches this block, exec
cout << "Caught " << excp;
}
catch (...) { //default case
cout << "Default Exception
";
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x=-1,y=1;
try
{
if(x<0)
{
throw("xisnegative");
}
}
catch(const char *exp)
{
cout<<exp<<endl;
}
try
{
if(y>0)
{
throw("yispositive");
}
}
catch(const char *exp)
{
cout<<exp<<endl;;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int x = -1;
// Some code
cout << "Before try
";
try {
cout << "Inside try
";
if (x < 0)
{
throw x;
cout << "After throw (Never executed)
";
}
}
catch (int x ) {
cout << "Exception Caught
";
}
cout << "After catch (Will be executed)
";
return 0;
}
#include fuck
Code Example |
---|
Cpp :: opengl draw semi circle c++ |
Cpp :: creare array con c++ |
Cpp :: Disabling console exit button c++ |
Cpp :: c++ looping through a vector |
Cpp :: c++ if example |
Cpp :: c++ vector remove all duplicate elements |
Cpp :: check if element in dict c++ |
Cpp :: quick sort |
Cpp :: gcc suppress warning inline |
Cpp :: Visual studio code include path not working c++ |
Cpp :: c++ finding gcd |
Cpp :: c++ for loop multiple variables |
Cpp :: vector iterating in c++ |
Cpp :: vectors c++ |
Cpp :: C++ Integer Input/Output |
Cpp :: c++ integer array |
Cpp :: tuple vector c++ |
Cpp :: c++ inheritance constructor |
Cpp :: linux c++ sigint handler |
Cpp :: one away coding question |
Cpp :: QVariant to int |
Cpp :: c++ get data type |
Cpp :: char array declaration c++ |
Cpp :: c++ garbage collection |
Cpp :: c++ compare type |
Cpp :: max heap insertion c++ |
Cpp :: get function in cpp. |
Cpp :: C++, binary search recursive |
Cpp :: merge sort in descending order c++ |
Cpp :: unique element in array in c |