How can you handle exceptions in java | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 46

How can you handle exceptions in java

Handle java exceptions

18th May 2019, 11:57 AM
Rapt[#Demure]
Rapt[#Demure] - avatar
23 Réponses
+ 36
There are five keywords used to handle exceptions in Java:  try catch finally throw throws
18th May 2019, 5:46 PM
Rapt[#Demure]
Rapt[#Demure] - avatar
+ 27
Set your language to arabic
19th May 2019, 5:19 AM
Rapt[#Demure]
Rapt[#Demure] - avatar
18th May 2019, 12:42 PM
Kelvin Paul
Kelvin Paul - avatar
+ 13
You can also have look into this code: https://code.sololearn.com/cE5BpKwo33DN/?ref=app
18th May 2019, 12:48 PM
Denise Roßberg
Denise Roßberg - avatar
+ 10
Using try catch for example.
19th May 2019, 9:47 PM
Sonic
Sonic - avatar
+ 8
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").
19th May 2019, 1:25 AM
PacoB
PacoB - avatar
+ 7
exceptions keywords: try finally catch throw throws
19th May 2019, 5:33 PM
CodeFu
CodeFu - avatar
+ 7
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.
20th May 2019, 2:11 AM
Shashank Sharma
Shashank Sharma - avatar
+ 6
walid No. Only english, russian and spanish.
19th May 2019, 9:11 AM
Denise Roßberg
Denise Roßberg - avatar
+ 6
In Java Programming Language, exceptions can be handled using 5 keywords: 1. try 2. catch 3. finally 4. throw 5. throws
19th May 2019, 9:13 AM
Vaishnavi Rajkumar Pawar
+ 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
19th May 2019, 2:52 PM
Ashish Mewada
Ashish Mewada - avatar
+ 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.
19th May 2019, 2:43 AM
Pravallika
+ 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.
19th May 2019, 4:24 AM
Mewan Athukorala
Mewan Athukorala - avatar
+ 5
Try catch Finally Through Throws Just memorize like a song then your good to go ūüėÉ
19th May 2019, 5:53 PM
Chukwunweike David Obi
Chukwunweike David Obi - avatar
+ 4
Does Arabic exist in this application? ūüėĘūüėĘūüėĘ
19th May 2019, 5:01 AM
walid
+ 4
If you are using spring you can use annotation @ExceptionHandler :)
19th May 2019, 9:45 AM
Michal
Michal - avatar
19th May 2019, 6:05 PM
Leo Tornato
Leo Tornato - avatar
+ 4
There are five keywords used to handle exceptions in Java: try catch finally throw throws It is correct
8th Oct 2019, 6:53 AM
Mewan Athukorala
Mewan Athukorala - avatar
+ 3
Try catch Finally Through Throws Just memorize like a song then your good to go ūüėÉ
20th May 2019, 11:51 AM
Canal AMPM
Canal AMPM - avatar
+ 3
Using try{} catch{} block you can easily handle any type of exceptions in java We can have multiple catch block in single try block
24th Jun 2019, 5:19 PM
Ratan Kumawat
Ratan Kumawat - avatar