Difference between try-catch and throw in java

前端 未结 8 444
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 10:02

What is the difference between try-catch and throw clause. When to use these?

Please let me know .

8条回答
  •  不思量自难忘°
    2020-12-07 10:54

    All these keywords try, catch and throw are related to the exception handling concept in java. An exception is an event that occurs during the execution of programs. Exception disrupts the normal flow of an application. Exception handling is a mechanism used to handle the exception so that the normal flow of application can be maintained. Try-catch block is used to handle the exception. In a try block, we write the code which may throw an exception and in catch block we write code to handle that exception. Throw keyword is used to explicitly throw an exception. Generally, throw keyword is used to throw user defined exceptions.

    For more detail visit Java tutorial for beginners.

提交回复
热议问题