JAVA Exception Handling

Exception handling is the way to handle the unexpected circumstances like runtime errors. So when the unexpected circumstance occurs, the program control is transferred to special functions known as handlers.

Syntax:

try{  
// the protected code. 
} 

Catch(Exception_Name){ 
// the code to run when unexpected circumstance occurs. 
} 

C++ EXCEPTION HANDLING KEYWORDS

  • try
  • catch, and
  • throw
  1. try:-A try block identifies a block of code for which particular exceptions will be activated. It’s followed by one or more catch blocks.
  2. throw:-A program throws an exception when a problem shows up. This is done using a throw keyword.

  3. catch:-A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.