Skip to content

Commit

Permalink
throw runtime exception on invalid parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
gubatron committed Mar 1, 2015
1 parent 294a265 commit ff773af
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/com/frostwire/jlibtorrent/TorrentInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ public TorrentInfo(byte[] bencodedBytes) {
lazy_entry lentry = new lazy_entry();
error_code ec = new error_code();
lazy_entry.bdecode(Vectors.bytes2char_vector(bencodedBytes), lentry, ec);
this.ti = new torrent_info(lentry);

if (ec.value() != 0) {
this.ti = null;
throw new RuntimeException(ec.message());
} else {
this.ti = new torrent_info(lentry);
}
}

/**
Expand Down

3 comments on commit ff773af

@gubatron
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldenml I'm not sure if this is what you had in mind.

Didn't want to add an InvalidParameterException because then I'd have to change the signature and have try/catch everywhere.... but I guess that's the right thing to do. Let me know.

@aldenml
Copy link
Collaborator

@aldenml aldenml commented on ff773af Mar 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalArgumentException is the one, it inherits from RuntimeException and there is no need of try catch.

@gubatron
Copy link
Collaborator Author

@gubatron gubatron commented on ff773af Mar 2, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.