tag:blogger.com,1999:blog-8712770457197348465.post6449881115694334307..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: How to use Java 1. 7 Multiple Catch Block with example - Tutorialjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-8712770457197348465.post-53115015719319266822017-02-01T10:05:00.309-08:002017-02-01T10:05:00.309-08:00I even got the same error, please correct the prog...I even got the same error, please correct the programrama krishnahttps://www.blogger.com/profile/06378531388221747267noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-51940867912914133232015-09-08T05:07:16.474-07:002015-09-08T05:07:16.474-07:00The above sample code can't compile due to &qu...The above sample code can't compile due to "The exception NumberFormatException is already caught by the alternative IllegalArgumentException" error. <br /><br />Because NumberFormatException is sub-type of IllegalArgumentException.<br /><br />I was curies to know how the sample ouput was got for the author of the above example?<br /><br />Bajihttps://www.blogger.com/profile/03853332634035007868noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-69992098717951220302015-05-31T01:17:16.038-07:002015-05-31T01:17:16.038-07:00@Ashudeep while joining multiple exceptions we nee...@Ashudeep while joining multiple exceptions we need to ensure that exceptions are disjoint ie there is no parent-child relationship b/w them.The example give by you...even if you reverse the order .....it will give compilation error because if you want to execute a particular catch block...lets say on Arithmetic exception...even if u only specify Exception the same block will be executed.vishal singhhttps://www.blogger.com/profile/08752370535526772989noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-34381524155662453302015-05-23T06:59:21.477-07:002015-05-23T06:59:21.477-07:00To Add one more point –
While joining multiple sta...To Add one more point –<br />While joining multiple statement using | make sure that you go from subtype exception class to parent exception classes. Doing something like this will result in compiler error.<br /><br />// This will give compiler error<br />catch(Exception | ArithmeticException | ArrayIndexOutOfBoundsException ex){<br />ex.printStackTrace();<br />}Anshudeephttp://netjs.blogspot.com/noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-26686129670744698092014-12-11T04:41:47.583-08:002014-12-11T04:41:47.583-08:00Hello @vivek, what error you get, can you please p...Hello @vivek, what error you get, can you please post it hereJavinnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10391945237330621702014-12-11T03:39:53.710-08:002014-12-11T03:39:53.710-08:00It gives error... at the compile time..... It gives error... at the compile time..... viveksoundararajanhttps://www.blogger.com/profile/02349379870628932627noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75485173425292625432014-05-07T10:59:48.728-07:002014-05-07T10:59:48.728-07:00I am trying to do the above program but i am getti...I am trying to do the above program but i am getting compile time error "The exception NumberFormatException is already caught by the alternative exception IllegalArgumentException".Please help me how to resolve thisAnonymoushttps://www.blogger.com/profile/09382047004251139032noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-26380783427891553822014-01-08T10:37:36.405-08:002014-01-08T10:37:36.405-08:00As said, this post is more than 2 years old but is...As said, this post is more than 2 years old but isn't worth of mentioning that: NumberFormatException is a subclass of IllegalArgumentException and the compiler issues an error related to multi-catch statement using the subclassing? I think the author must replace just the code not his or her comments.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-222644219361256342013-08-16T05:08:47.264-07:002013-08-16T05:08:47.264-07:00@Anonymous, Welcome to Javarevisited. Thanks for p...@Anonymous, Welcome to Javarevisited. Thanks for pointing that out, some how that missed correcting that to catch. Glad to see your attention of detail :).Javin @ Parse String to int in Javahttp://javarevisited.blogspot.com/2011/08/convert-string-to-integer-to-string.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-8683972266817362362013-08-16T04:39:23.266-07:002013-08-16T04:39:23.266-07:00This blog entry is 2 years old and STILL you haven...This blog entry is 2 years old and STILL you haven't corrected your use of "CACHE" to "CATCH".<br />What does that say about your attention to detail at work? I'm glad you're not one of my coders.<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-27134785752415271522013-08-10T08:25:02.538-07:002013-08-10T08:25:02.538-07:00Hi Amit, have you set Java source level to 1.7 as ...Hi Amit, have you set Java source level to 1.7 as this functionality is only present in Java 1.7? If you are using Eclipse, it's worth to check compiler settings. You can also post your code and some more details, and I will try to help you out.Javin @ 32-bit vs 64-bit JVMhttp://javarevisited.blogspot.com/2012/01/find-jvm-is-32-or-64-bit-java-program.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10333969607670072102013-08-10T06:41:18.278-07:002013-08-10T06:41:18.278-07:00But in the code NumberFormatException and IllegalA...But in the code NumberFormatException and IllegalArguementException gives error... at the compile time.....Anonymoushttps://www.blogger.com/profile/12272945767507100815noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-91059125052194904132013-05-29T05:06:32.494-07:002013-05-29T05:06:32.494-07:00@Subrat just use multiple catch statements like be...@Subrat just use multiple catch statements like before. The new functionality is only there if you want to do much the same thing in every case.<br />About mehttps://www.blogger.com/profile/09439264779989018408noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-42910227438584140792013-05-20T08:49:27.322-07:002013-05-20T08:49:27.322-07:00how to provide different implementation for differ...how to provide different implementation for different type exception.<br />eg.<br />try{}<br />catch(IOException |FileNotFoundException| AWTException ex)<br /> in the above code if we want to provide different handle each exception, how can we handle that with one exception instance ex?<br />Can you please provide the solution with example?Subrathttps://www.blogger.com/profile/12083403244483727471noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-27432093549393875532012-07-31T07:45:03.867-07:002012-07-31T07:45:03.867-07:00Thanks Ujwol for pointing that its indeed meant to...Thanks Ujwol for pointing that its indeed meant to catch multiple Exceptions in Java and that's why called multi-catch in common language.Javin @ transient vs volatilehttp://javarevisited.blogspot.sg/2012/03/difference-between-transient-and.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-51585860467667027972012-07-31T06:58:48.402-07:002012-07-31T06:58:48.402-07:00Nice read..But please correct..it is not "Mul...Nice read..But please correct..it is not "Multi-Cache" ..it is "Multi-Catch"Ujwol Shresthahttps://www.blogger.com/profile/16475183195471254998noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75540894196609619762011-07-28T13:55:43.704-07:002011-07-28T13:55:43.704-07:00"Multi-CACHE" block, eh dude? Brilliant...."Multi-CACHE" block, eh dude? Brilliant.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-45959060969472693052011-07-26T18:20:51.878-07:002011-07-26T18:20:51.878-07:00I agree with you multi-cache block has improved ex...I agree with you multi-cache block has improved exception handling and made code more cleaner. JDK7 project coin is worth of money.Anonymousnoreply@blogger.com