Skip to main content

Posts

Showing posts from May, 2014

Advanced C++ - Exceptions

Exception handling is programming feature helpful for programmers to handle run time error conditions. Run time error conditions can be like division by zero, unable to allocate memory due to scarcity, trying to open a file which doesn’t exist etc. There are two types of exceptions. One is Standard exceptions provided by C++ Standard library and other type is User defined exceptions. Now, to handle any exception, we should understand 3 main block of exception statement which are as follows: throw block - in this block, we throw an exception. The operand of the throw statement decides the type of exception occurred. Once this line is executed, program jumps to catch block to handle the exception occurred. catch block - is the block where we handle exception. This is also called as exception handler and this block is written immediately after the try block as shown in example. This can be written similar to a normal function with at leas