Every programme goes off for error . when we write hundreads line of code but one error occur in the code then the rest of the code is not exucated. To avoid this occur we use try catch method . So at first we should know what is error.
The program may stop due to a mistake in the program then we can call it error. If any user give wrong input then the programme can be stopped .Beside the server can not give response correct time then also occur error.
When any error occur in any programme then we use error handling to avoid this. Because error handling makes easier a user to execute to his programme. so you don’t have to look up the design when you write and later maintain the code.
The try statement allows you to define a block of code to be tested for errors while it is being executed. The catch statement allows you to define a block of code to be executed, if an error occurs in the try block.
In the figure we can see the programme can not execute because we here c is not defined . To avoid this we can use try catch method.
In the above figure use try catch method . Here c is not defined , but the programme is executed. Because when we use try method the programme is executed if any error cause of in programme . If any error cause of in programme then it show message.