You are on page 1of 1

Exception Handling in C++:

Runtime time error are called Exceptions and almost all OOP’s provide adequate methods to handle
these Exceptions.

Runtime Errors are caused by the user due to:

1. Bad input (Inputting String instead of Int).


2. Unavailability of resources. (like my program needs Internet and it is not there, printer is
needed but it is not connected or the ink tank is empty, some files on system are needed but
are deleted etc.)

So, the main function of exception handling is to give the user proper message so that he can
remove the error correctly.

In C++ throw statement is always required to throw the exception to the catch block.

When a throw statement is countered the execution of try stops and the control shifts to the catch
statement.

throw has to written in conditional statement such that for a particular input it gives error otherwise
it will be executed every time.

Try, Catch, Throw are mainly used so that two functions can communicate like if there is a exception
in a secondary function then it should tell the main function about it.

throw can throw any kind of data type value.

If 1.5 is written it is double and 1.5f is float.

You might also like