Question

I'm working on a Spotify puzzle (viewable here). I'm writing the solution in Java and I've gotten my code to pass their two example inputs in Eclipse, on ideone.com, and through Terminal on my osx, all without errors. However whenever I submit to the Spotify bot I get the following minimalist response:

We have tested your solution, and while doing so we unfortunately

discovered the following error: Run Time Error

An exception was not caught

Here's basically what I do to read in input:

scn = null;

try {
    scn = new Scanner(System.in);

      if(scn.hasNext()){
      strIn = scn.nextLine();
      //do work on first line of input
      }

      if(scn.hasNext()){
      strIn = scn.nextLine();
      //do work on second line of input
      }

      //do work on the rest of the lines
      while (scn.hasNext()) {
      strIn = scn.nextLine();

      if(/*reached last line*/){
           break;
      }
      }

  }

  catch(Exception e){
      System.out.println("Exception caught");
      System.out.println(e.getStackTrace());

  } finally {
      if (scn != null) {
          scn.close();
      }
  }

You can view my complete solution here. Note that my actual submission declares my class public, as per the Spotify submission guidelines.

Since the problem requires only simple I/O from stdin to stdout, it seems like I only need to account for any exceptions that may be thrown when I'm reading in input within my try block. I provide a catch block for all Exceptions (bad form I know) but shouldn't that handle it? Maybe I'm neglecting some exceptions that could be popping up elsewhere?

It may be that I'm not accounting for some small peculiarity about how the Spotify bots parse input, but their response message and guidelines make it hard to pinpoint where exactly the problem is. I apologize if this question is too localized - other Spotify puzzle questions were seen this way - but I figure my i/o and exceptons questions are broad enough, and perhaps people have some good answers on how the Spotify bots might work. Also, it's been a while since I've coded in Java, so any other comments are certainly welcome.

Was it helpful?

Solution

Just to make it official, the exception that was being raised was not an I/O exception, like I was thinking, but actually an integer overflow exception. I needed to change the data type of the variable holding track plays to a long from an int. The test data Spotify was using must have had really large numbers that my ints couldn't hold, and that's why the program kept breaking! Hope this helps people.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top