When I check in intellij I've got error "The program worked too long and was closed" on site it's just not pass testing error.

/* Exceptions
There’s a method that throws two exceptions inherited from Exception, and the other two inherited from RuntimeException: NullPointerException, ArithmeticException,
 FileNotFoundException, and URISyntaxException.

    You need to catch NullPointerException and FileNotFoundException, but not to catch ArithmeticException and URISyntaxException. How to do it?
*/

public class Solution
{
    public static void main(String[] args) throws Exception
    {
        //add your code here

        try
        {
            method1();
        }
        catch (NullPointerException e)
        {
            e.printStackTrace();
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }

        //add your code here

    }

    public static void method1() throws NullPointerException, ArithmeticException, FileNotFoundException, URISyntaxException
    {
        int i = (int) (Math.random() * 4);
        if (i == 0)
            throw new NullPointerException();
        if (i == 1)
            throw new ArithmeticException();
        if (i == 2)
            throw new FileNotFoundException();
        if (i == 3)
            throw new URISyntaxException("", "");
    }
}

asked 05 Aug '17, 17:12

genek's gravatar image

genek
173
accept rate: 0%

edited 05 Aug '17, 17:25


This works:

    try
        {
            method1();
        }
        catch (NullPointerException e)
        {

        }
        catch (FileNotFoundException e)
        {
;
        }
        //add your code here
link

answered 06 Aug '17, 07:42

genek's gravatar image

genek
173
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×53
×31
×11

Asked: 05 Aug '17, 17:12

Seen: 600 times

Last updated: 06 Aug '17, 07:42