Sharp Tutorial
exception in C++

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

introduction to c++

  • C++ Home
  • Introduction to C++
  • History features
  • Sample Programs
  • cout , cin , endl
  • Data type and Operators
  • if else in c++
  • loop in c++

Oops in C++

  • Object / Class
  • Constructor
  • Function & Constructor Overloading
  • Inheritance
  • Overriding

Advanced C++

  • Strings in C++
  • Exception Handling
  • Special Functions
  • C++ Programs

Exception in c++

Exception is the unwanted situation that disturb the normal flow the program eg divide by zero. 

C++ has three block try , catch and throw to handle the exceptions

try block:

it is the error prone block where an exception may occur.

catch block:

this is the block which executes if there is an exception in try block

catch block:

throw keyword throws the exception when there is a problem in try block

Exception program Example in c++

#include<iostream>
using namespace std;
int main() { try { int age ; cout<<"enter your age"; cin>>age; if (age<0) { throw (age); } else { cout<<"your age is "<<age; } } catch (int myAge) { cout << "Neagative age is not possible "<<myAge; return 0; }

Enquiry about Course

Ask your Question

Click Here

Sharp (2) Tutorials

Video/ C Introduction

Watch video in full size

Video tutorial

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial