protect function with exeption

This commit is contained in:
6543 2019-10-20 22:32:25 +02:00
parent cab7b33ca5
commit e9812f17ed
Signed by: 6543
GPG Key ID: A1CA74D27FD13271
1 changed files with 5 additions and 2 deletions

View File

@ -26,7 +26,7 @@ public enum Version {
Matcher m ;

if (!pattern_stable_release.matcher(min).find() || !pattern_stable_release.matcher(last).find()) {
throw new Error("VersionCheck: wrong format for min or last version given");
throw new IllegalArgumentException("VersionCheck: wrong format for min or last version given");
}

m = pattern_stable_release.matcher(value);
@ -74,7 +74,7 @@ public enum Version {

switch (range_check) {
case 2:
throw new Error("Minimum Version higher than Last Version");
throw new IllegalArgumentException("Minimum Version higher than Last Version");
case 1: //min == last
switch (min_check) {
case 0:
@ -101,6 +101,9 @@ public enum Version {
* 2 = more
*/
public static int compare(String A, String B) {
//throw new IllegalArgumentException
if((!A.matches("[0-9]+(\\.[0-9]+)*")) || (!B.matches("[0-9]+(\\.[0-9]+)*"))) throw new IllegalArgumentException("Invalid version format");

if (A.contains(".") || B.contains(".")) {
// example 2 vs 1.3
if (!(A.contains(".") && B.contains("."))) {