Skip to content

Commit b194a7b

Browse files
committed
Расширенные исключения
1 parent 5970d20 commit b194a7b

36 files changed

+209
-58
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.annimon.ownlang.exceptions;
2+
3+
public final class ArgumentsMismatchException extends RuntimeException {
4+
5+
public ArgumentsMismatchException() {
6+
}
7+
8+
public ArgumentsMismatchException(String message) {
9+
super(message);
10+
}
11+
}

src/com/annimon/ownlang/parser/LexerException.java renamed to src/com/annimon/ownlang/exceptions/LexerException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.annimon.ownlang.parser;
1+
package com.annimon.ownlang.exceptions;
22

33
/**
44
*
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.annimon.ownlang.exceptions;
2+
3+
public final class OperationIsNotSupportedException extends RuntimeException {
4+
5+
public OperationIsNotSupportedException(Object operation) {
6+
super("Operation " + operation + " is not supported");
7+
}
8+
}

src/com/annimon/ownlang/parser/ParseException.java renamed to src/com/annimon/ownlang/exceptions/ParseException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.annimon.ownlang.parser;
1+
package com.annimon.ownlang.exceptions;
22

33
/**
44
*
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.annimon.ownlang.exceptions;
2+
3+
public final class PatternMatchingException extends RuntimeException {
4+
5+
public PatternMatchingException() {
6+
}
7+
8+
public PatternMatchingException(String message) {
9+
super(message);
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.annimon.ownlang.exceptions;
2+
3+
public final class TypeException extends RuntimeException {
4+
5+
public TypeException(String message) {
6+
super(message);
7+
}
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.annimon.ownlang.exceptions;
2+
3+
public final class UnknownFunctionException extends RuntimeException {
4+
5+
private final String functionName;
6+
7+
public UnknownFunctionException(String name) {
8+
super("Unknown function " + name);
9+
this.functionName = name;
10+
}
11+
12+
public String getFunctionName() {
13+
return functionName;
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.annimon.ownlang.exceptions;
2+
3+
public final class VariableDoesNotExistsException extends RuntimeException {
4+
5+
private final String variable;
6+
7+
public VariableDoesNotExistsException(String variable) {
8+
super("Variable " + variable + " does not exists");
9+
this.variable = variable;
10+
}
11+
12+
public String getVariable() {
13+
return variable;
14+
}
15+
}

src/com/annimon/ownlang/lib/ArrayValue.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.annimon.ownlang.lib;
22

3+
import com.annimon.ownlang.exceptions.TypeException;
34
import java.util.Arrays;
45
import java.util.Iterator;
56

@@ -61,7 +62,7 @@ public void set(int index, Value value) {
6162

6263
@Override
6364
public double asNumber() {
64-
throw new RuntimeException("Cannot cast array to number");
65+
throw new TypeException("Cannot cast array to number");
6566
}
6667

6768
@Override

src/com/annimon/ownlang/lib/FunctionValue.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.annimon.ownlang.lib;
22

3+
import com.annimon.ownlang.exceptions.TypeException;
34
import java.util.Objects;
45

56
/**
@@ -23,7 +24,7 @@ public int type() {
2324

2425
@Override
2526
public double asNumber() {
26-
throw new RuntimeException("Cannot cast function to number");
27+
throw new TypeException("Cannot cast function to number");
2728
}
2829

2930
@Override

0 commit comments

Comments
 (0)