Skip to content

Commit

Permalink
Add messages to exception constructor calls.
Browse files Browse the repository at this point in the history
I hadn't been aware that NoSuchElementException could *take* a message.
  • Loading branch information
kingjon3377 committed Oct 9, 2023
1 parent 6651969 commit 58b6bbe
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public boolean hasNext() {
public Type next() {
if (switched) {
if (counter <= 0) {
throw new NoSuchElementException();
throw new NoSuchElementException("Ran out of items");
} else {
counter--;
return nothingValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public T next() {
wrapped.removeFirst();
}
}
throw new NoSuchElementException();
throw new NoSuchElementException("All iterators exhausted.");
}
}
}
2 changes: 1 addition & 1 deletion lovelace-util/src/main/java/lovelace/util/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Integer next() {
current++;
return current;
} else {
throw new NoSuchElementException();
throw new NoSuchElementException("Finished the range");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lovelace-util/src/main/java/lovelace/util/TypeStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Class<?> next() {
return item;
}
}
throw new NoSuchElementException();
throw new NoSuchElementException("No more supertypes");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public void close() throws IOException {
@Override
public XMLEvent next() throws NoSuchElementException {
if (closed) {
throw new NoSuchElementException();
throw new NoSuchElementException("Reader is closed");
} else {
try {
if (wrapped.hasNext()) {
final XMLEvent retval = wrapped.nextEvent();
if (retval == null) {
close();
throw new NoSuchElementException();
throw new NoSuchElementException("End of input");
} else {
if (!wrapped.hasNext()) {
close();
Expand All @@ -88,7 +88,7 @@ public XMLEvent next() throws NoSuchElementException {
}
} else {
close();
throw new NoSuchElementException();
throw new NoSuchElementException("End of input");
}
} catch (final XMLStreamException exception) {
final Throwable cause = exception.getCause();
Expand Down
2 changes: 1 addition & 1 deletion model/src/main/java/common/map/PointIterable.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean hasNext() {
@Override
public Point next() throws NoSuchElementException {
if (started && row == startRow && column == startColumn) {
throw new NoSuchElementException();
throw new NoSuchElementException("Iteration finished");
} else {
started = true;
if (horizontal) {
Expand Down
4 changes: 2 additions & 2 deletions model/src/main/java/common/map/SPMapNG.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public void removeRivers(final Point location, final River... removedRivers) {
public boolean addFixture(final Point location, final TileFixture fixture) {
if (fixture instanceof FakeFixture) {
LovelaceLogger.error("Fake fixture passed to SPMapNG.addFixture()");
LovelaceLogger.debug(new Exception(), "Stack trace for fake fixture in SPMapNG.addFixture()");
LovelaceLogger.debug(new Exception("Fake fixture"), "Stack trace for fake fixture in SPMapNG.addFixture()");
return false;
}
modified = true; // TODO: Only if this is a change
Expand All @@ -490,7 +490,7 @@ public boolean addFixture(final Point location, final TileFixture fixture) {
local.add(fixture);
fixturesMap.put(location, local);
LovelaceLogger.warning("Inserted duplicate-ID fixture at %s", location);
LovelaceLogger.debug(new Exception(), "Stack trace of this location: ");
LovelaceLogger.debug(new Exception("Duplicate ID"), "Stack trace of this location: ");
LovelaceLogger.info("Existing fixture was: %s", existing.get().getShortDescription());
LovelaceLogger.info("Added: %s", fixture.getShortDescription());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ProxyJob(final String name, final boolean parallel, final IWorker... prox
.findAny().orElse(job));
} else if (unmodified) {
LovelaceLogger.warning("Can't add job to immutable worker");
LovelaceLogger.trace(new Exception(), "Stack trace for immutable-worker condition");
LovelaceLogger.trace(new Exception("Can't add job to immutable worker"), "Stack trace for immutable-worker condition");
}
}

Expand Down

0 comments on commit 58b6bbe

Please sign in to comment.