ThermalCube
0
Q:

try catch in c++

try {
	//do
} catch (...){
	//if error do
}
4

    try {
  int age = 15;
  if (age > 18) {
    
    cout << "Access granted - you are old enough.";
  } else {
    
    throw 505;
  }
}
catch (int myNum) {
  
    cout << "Access denied - You must be at least 18 years old.\n";
  
    cout << "Error number: " << myNum; 
} 
2
#include <iostream> 
using namespace std; 
  
int main() 
{ 
    try  { 
       throw 10; 
    } 
    catch (char *excp)  { 
        cout << "Caught " << excp; 
    } 
    catch (...)  { 
        cout << "Default Exception\n"; 
    } 
    return 0; 
}
1

New to Communities?

Join the community