tag:blogger.com,1999:blog-8712770457197348465.post7176920819982777948..comments2024-03-28T02:47:19.159-07:00Comments on Javarevisited: Difference between throw and throws in Exception handling - Java Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-8712770457197348465.post-14487379740971857792015-09-30T06:27:52.491-07:002015-09-30T06:27:52.491-07:00Very nice & perfect explanation. . ThanksVery nice & perfect explanation. . ThanksAnonymoushttps://www.blogger.com/profile/18141297396685779128noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-86733509418306299222015-09-30T06:01:16.245-07:002015-09-30T06:01:16.245-07:00@Tushar, throw return the control back to the call...@Tushar, throw return the control back to the caller, acting like a break in the switch statement. In your example, if you pass 1 or 2 then they will throw Exception, since you don't have default case, nothing will happen if you pass any number other than 1 and 2.javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-66382689491759745512015-09-29T23:39:27.417-07:002015-09-29T23:39:27.417-07:00Please anyone can explain me how throw keyword is ...Please anyone can explain me how throw keyword is used to break switch statement<br />int number = 5;<br />switch(number){<br /> case 1:<br /> throw new RuntimeException("Exception number 1");<br /> case 2:<br /> throw new RuntimeException("Exception number 2");<br /> }Anonymoushttps://www.blogger.com/profile/18141297396685779128noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-70550785034448005932015-01-15T23:05:49.487-08:002015-01-15T23:05:49.487-08:00number 3 does NOT make sense...are you missing som...number 3 does NOT make sense...are you missing some words in that sentence. Sounds "run-off"ishAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-24222177635449377022015-01-15T07:55:46.372-08:002015-01-15T07:55:46.372-08:00In exceptional handling throw keyword is best used...In exceptional handling throw keyword is best used only for checked exceptions <br />ie compile time exceptions<br /><br />throw keyword doesnot handle runtime exceptions like ArithmeticException etc. <br /><br />throw keyword will throw the said exception and stops where as try catch methods will handle runtime exceptions and continues <br />the regular <br />flow of the program<br /><br /><br /Pemanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-76074767617356582242015-01-15T07:55:06.364-08:002015-01-15T07:55:06.364-08:00import java.io.IOException;
class Testthrows1{ ...import java.io.IOException; <br />class Testthrows1{ <br /> void m()throws IOException{ <br /> throw new IOException("device error");//checked exception <br /> } <br /> void n()throws IOException{ <br /> m(); <br /> } <br /> void p(){ <br /> try{ <br /> n(); <br /> }catch(Exception e){System.out.println("exception handled");} <br /> } <br /> Pemanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-81585768187407570892014-07-01T08:43:01.530-07:002014-07-01T08:43:01.530-07:00I know that, error and exceptions are the problems...I know that, error and exceptions are the problems in java coding, then why we generate Exceptions manually using this 'throw' keyword?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-9140809946941933822014-05-05T23:23:04.307-07:002014-05-05T23:23:04.307-07:00can anyone please briefly explain the difference b...can anyone please briefly explain the difference between throw and thrown..... still i can't understand...Anonymoushttps://www.blogger.com/profile/09515713500471985965noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-29301491298459247762014-03-16T14:25:26.649-07:002014-03-16T14:25:26.649-07:00Can anyone please explain the diff....i still dont...Can anyone please explain the diff....i still dont understandAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82663872490664172332013-08-28T00:49:32.104-07:002013-08-28T00:49:32.104-07:00Throw is used create custom exceptionThrow is used create custom exceptionAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-78528166849255704132012-12-17T10:00:09.454-08:002012-12-17T10:00:09.454-08:00how is message is print in the custom exception??
...how is message is print in the custom exception??<br />as we didnt use System.out.println??nitin rawathttps://www.blogger.com/profile/09965262080752522490noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-85530013336193720222012-11-08T09:18:07.405-08:002012-11-08T09:18:07.405-08:00'throws' is always used with a method and ...'throws' is always used with a method and specifies this method may raise given exception(exception name followed by keyword throws)..<br />throw is used to raise an exception manually..<br />rajhttps://www.blogger.com/profile/01118303263773511824noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-4386413774958822682012-07-31T00:19:56.558-07:002012-07-31T00:19:56.558-07:00Can we throw Errors in Java ? like throw java.lang...Can we throw Errors in Java ? like throw java.lang.OutOfMemroyError etcAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-54780583852313816992012-06-11T20:08:51.883-07:002012-06-11T20:08:51.883-07:00Can you please give an example of throw and throws...Can you please give an example of throw and throws, to understand difference between them better ? My understanding of throw is very limited but I know we can also use throw not just to throw exception but also to return from method or switch block.Praneetihttp://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-13350122828137910332012-04-16T01:18:33.801-07:002012-04-16T01:18:33.801-07:00throw vs throws, throw and throws in Java, throws ...throw vs throws, throw and throws in Java, throws vs throw in Java, throw vs throws in Java, difference between throw and throws in Java, difference between throw and throws, what are differences between throw and throws, when to use throw and when to use throws in JavaAnonymousnoreply@blogger.com