+35

How can you handle exceptions in java

Handle java exceptions

5/18/2019 11:57:38 AM

👩‍💻Learner👨‍💻

22 Answers

New Answer

+47

Simple example sister do division and take denominator as zero u will get error after that u put that total block from operation into try block later u go vth catch block.😊 It is very interesting topic. And stack overflow concept is awesome 👍👍

+33

There are five keywords used to handle exceptions in Java:  try catch finally throw throws

+25

Set your language to arabic

+13

You can also have look into this code: https://code.sololearn.com/cE5BpKwo33DN/?ref=app

+12

Using try catch block https://www.sololearn.com/learn/Java/2175/

+10

Using try catch for example.

+7

Using a try catch block is the most accepted way to handle exceptions. However, using the expression "throws" next to the method's name (for example "public void Method() throws InterruptedException {}) is also accepted. For small methods, I suggest using the throws Exception for less syntax. However, in methods with different exceptions to handle, it is preferable to use try-catch (and in the case also "finally").

+6

walid No. Only english, russian and spanish.

+6

In Java Programming Language, exceptions can be handled using 5 keywords: 1. try 2. catch 3. finally 4. throw 5. throws

+6

Hii Muhammad Reshma, We can handle exceptions in java. There are five keyword that use we can handle exceptions. 1:- try 2:- catch 3:- finally 4:- throw 5:- throws

+6

exceptions keywords: try finally catch throw throws

+6

To handle exceptions, java provides five keywords i.e. try, catch, throw, throws and finally. The code to be handled for exception is put inside the try block. For a try block, there is a catch block which shows msg or anything you wanna do when exception occurs. You may have multiple catch block for a single try block. And put catch from most specified to most common one. throw is used to throw self generated exceptions. for eg. In a function of division, if the user gives denominator as zero throw an arithmetic exception. Throws is used for checked exceptions. Where there is a possibility for an exception to occur. Now there are some things which you want to do even if exception occurs, they are kept inside finally block for eg. in file handling whether or not exception occur or not you should close a file.

+5

is there any chance to get errors place them in try block. if error occurs then it enter into catch block without checking remaining statements in try block. Finally is a keyword it is executed compulsory either the exception raises or not.

+5

is there are so many errors ,we can place them in try block.if error happen we can put in to catch block without checking other statements in try block.Finally is a keyword.

+5

Try catch Finally Through Throws Just memorize like a song then your good to go 😃

+4

Does Arabic exist in this application? 😢😢😢

+4

If you are using spring you can use annotation @ExceptionHandler :)

+4

https://dowork-zone.com/?mref=leotornato

+2

for validate Model attributes I use javax.validation @NotBlank and @NotNull, @NotEmpty. for handle other Exceptions you can use try catch throw throws finally

+2

Try catch Finally Through Throws Just memorize like a song then your good to go 😃