+ 4

whats the difference between throws exception and try catch

18th Jul 2016, 2:43 PM
UdhayaISRO
UdhayaISRO - avatar
5 Antworten
+ 2
In simple Way try is used for RISKY CODE where a programmes can think that There may be a chance Of occurring Exeption then Programmer will use try block and if there is any Exception occurs like (Division /O) then it will Throw that exception to CATCH block and Catch is use to varify exception type and Handle It. #Every try must have atleast 1 Catch or finally or Both.. #Throws block never handle any exception It only Delegate the Exception to Main method or Caller method..
6th Nov 2016, 6:44 PM
Mukesh Kumaar
Mukesh Kumaar - avatar
+ 2
Hi, if an exception occurs inside a function, that is declared to throw an exception in some cases (e.g. public void func() throws exception {...}), this exception will be given to the calling method, instead of being handled within the current method. If an error occurs in a try-block, it will be given to the catch-block and is handled there (if the error-type is declared in the catch-head).
9th Nov 2016, 7:48 PM
Thorsten
Thorsten - avatar
0
please go through exception handing and multiple exception topic once again. Even after that if you have any issue do point it out.
18th Jul 2016, 9:58 PM
Amit Karn
Amit Karn - avatar
0
Hello, Throws exception is not important to throw but catch exception is so import i will give an example to you If i have a method in example.java and it make divided operation and i didnot male any if coondation here there is an runtime exception because if tge user enter the second number 0 the program will stop because in math we cannot divid on zero so we write throws ....exception next to method declare this is throw and we know that methode block arenot make any thing untill i use it like example(); I will catch the exception when i go to use it in any other place like main i make like that try{ divided(); } catch(Exception e) { //anything } Btw you can catch the method without throw exception but i used in ligcat to know where is the error in your code (in larges apps)
19th Jul 2016, 8:45 AM
Mostafa Abobakr
Mostafa Abobakr - avatar
- 1
fjb to the RS
2nd Oct 2016, 4:45 PM
manohar kr singh
manohar kr singh - avatar