0

I am using a JDK 1.8 and I am facing a compilation problem something like below, when using multicatch.

Multiple markets in this line: Syntax error in token "|",. expected FileNotFoundException.IOException cannot be resolved to a type.

I checked a few related threads for multicatch but could not find the reason why I am facing this problem.

try
{
        try
        {
           //LOGIC
        } 
       finally
       {
       }
}catch ( FileNotFoundException | IOException e) {
           //EXCEPTION HANDLING                     
        }

PFA the screen grab to show the JDK version configured and the multi-catch throwing the exception.

enter image description here

@Tunaki - With individual catch statements it is working fine. I don't think it is because the finally block is before the catch block- PFB the screengrab:

enter image description here

bitemouth
  • 123
  • 8
  • 2
    This has nothing to do with the use of the multi-catch. The syntax of the try-catch-finally is just incorrect. See the linked question. – Tunaki Nov 14 '16 at 10:40
  • 1
    on a Sidenode, your IDE will probably tell you that the `IOException` already includes the catch of the `FileNotFoundException`, as `FileNotFoundException` inherits from `IOException` and wont compile the code. – SomeJavaGuy Nov 14 '16 at 10:41
  • The `catch` block should be **before** finally – Piotr Sołtysiak Nov 14 '16 at 10:42
  • @Piotr - When I don't user multi-catch, it is working fine. – bitemouth Nov 14 '16 at 10:46
  • @Piotr - I have uploaded a screengrab without multi-catch – bitemouth Nov 14 '16 at 10:50
  • Please use formatter. I cant read your code because of lack of indentation. – Muzaffer Nov 14 '16 at 10:53
  • @wisemann I have shown a screengrab for showing the exception alone. I have re-written the code block, so my question is understandable. – bitemouth Nov 14 '16 at 12:12
  • 1
    @Tunaki - I don't think this is a duplicate. Pls check once again and mark accordingly. – bitemouth Nov 14 '16 at 12:15
  • Yes this is not a duplication of that question. @Gnz Types in multi-catch must be disjoint. Because these exceptions are subclass of the other. You can not join them. This is a logical mistake. Option 1: disjoint them, option 2: remove FileNotFoundException.(IOException is superior then FNFEx) – Muzaffer Nov 14 '16 at 13:46
  • 1
    This wasn't clear at all with the initial revision, but please refer to http://stackoverflow.com/questions/32345287/not-able-to-use-multi-catch-from-java-effectively for the explanation of this. There is no need to reopen this. – Tunaki Nov 14 '16 at 14:23
  • @wisemann , [at]kevin-esche [at]Tunaki Thanks - I understand that subclassed exceptions could not be multi-catched. But shouldn't the compilation error thrown should be stating that? Instead, I am getting something else... Can you clarify on that if possible? – bitemouth Nov 14 '16 at 17:14

0 Answers0