Skip to content

Commit e304aaf

Browse files
committed
Replace RuntimeException with OwnLangRuntimeException in modules
1 parent d3dd8fe commit e304aaf

File tree

17 files changed

+70
-50
lines changed

17 files changed

+70
-50
lines changed

modules/main/src/main/java/com/annimon/ownlang/modules/date/date.java

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

3+
import com.annimon.ownlang.exceptions.OwnLangRuntimeException;
34
import com.annimon.ownlang.exceptions.TypeException;
45
import com.annimon.ownlang.lib.*;
56
import com.annimon.ownlang.modules.Module;
@@ -274,7 +275,7 @@ public Value execute(Value[] args) {
274275
try {
275276
return DateValue.from(format.parse(args[0].asString()));
276277
} catch (ParseException ex) {
277-
throw new RuntimeException(ex);
278+
throw new OwnLangRuntimeException(ex);
278279
}
279280
}
280281
}

modules/main/src/main/java/com/annimon/ownlang/modules/forms/JTextAreaValue.java

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

3+
import com.annimon.ownlang.exceptions.OwnLangRuntimeException;
34
import com.annimon.ownlang.lib.Arguments;
45
import static com.annimon.ownlang.lib.Converters.*;
56
import com.annimon.ownlang.lib.FunctionValue;
@@ -55,7 +56,7 @@ private FunctionValue offsetFunction(OffsetFunction f) {
5556
int result = f.accept(args[0].asInt());
5657
return NumberValue.of(result);
5758
} catch (BadLocationException ex) {
58-
throw new RuntimeException(ex);
59+
throw new OwnLangRuntimeException(ex);
5960
}
6061
});
6162
}

modules/main/src/main/java/com/annimon/ownlang/modules/gzip/gzip.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.annimon.ownlang.modules.gzip;
22

3+
import com.annimon.ownlang.exceptions.OwnLangRuntimeException;
34
import com.annimon.ownlang.exceptions.TypeException;
45
import com.annimon.ownlang.lib.*;
56
import com.annimon.ownlang.modules.Module;
@@ -45,7 +46,7 @@ private Value gzipFile(Value[] args) {
4546
gzos.finish();
4647
return NumberValue.ONE;
4748
} catch (IOException ex) {
48-
throw new RuntimeException("gzipFile", ex);
49+
throw new OwnLangRuntimeException("gzipFile", ex);
4950
}
5051
}
5152

@@ -63,7 +64,7 @@ private Value gzipBytes(Value[] args) {
6364
gzos.finish();
6465
return ArrayValue.of(baos.toByteArray());
6566
} catch (IOException ex) {
66-
throw new RuntimeException("gzipBytes", ex);
67+
throw new OwnLangRuntimeException("gzipBytes", ex);
6768
}
6869
}
6970

@@ -85,7 +86,7 @@ private Value ungzipFile(Value[] args) {
8586
copy(gzis, os);
8687
return NumberValue.ONE;
8788
} catch (IOException ex) {
88-
throw new RuntimeException("ungzipFile", ex);
89+
throw new OwnLangRuntimeException("ungzipFile", ex);
8990
}
9091
}
9192

@@ -102,7 +103,7 @@ private Value ungzipBytes(Value[] args) {
102103
copy(gzis, baos);
103104
return ArrayValue.of(baos.toByteArray());
104105
} catch (IOException ex) {
105-
throw new RuntimeException("ungzipBytes", ex);
106+
throw new OwnLangRuntimeException("ungzipBytes", ex);
106107
}
107108
}
108109

modules/main/src/main/java/com/annimon/ownlang/modules/java/java.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.annimon.ownlang.modules.java;
22

3+
import com.annimon.ownlang.exceptions.OwnLangRuntimeException;
34
import com.annimon.ownlang.lib.*;
45
import com.annimon.ownlang.modules.Module;
56
import java.lang.reflect.Array;
@@ -245,7 +246,7 @@ private Value newClass(Value[] args) {
245246
try {
246247
return new ClassValue(Class.forName(className));
247248
} catch (ClassNotFoundException ce) {
248-
throw new RuntimeException("Class " + className + " not found.", ce);
249+
throw new OwnLangRuntimeException("Class " + className + " not found.", ce);
249250
}
250251
}
251252

@@ -307,7 +308,7 @@ private static Value findConstructorAndInstantiate(Value[] args, Constructor<?>[
307308
// skip
308309
}
309310
}
310-
throw new RuntimeException("Constructor for " + args.length + " arguments"
311+
throw new OwnLangRuntimeException("Constructor for " + args.length + " arguments"
311312
+ " not found or non accessible");
312313
}
313314

@@ -327,7 +328,7 @@ private static Function methodsToFunction(Object object, List<Method> methods) {
327328
}
328329
}
329330
final String className = (object == null ? "null" : object.getClass().getName());
330-
throw new RuntimeException("Method for " + args.length + " arguments"
331+
throw new OwnLangRuntimeException("Method for " + args.length + " arguments"
331332
+ " not found or non accessible in " + className);
332333
};
333334
}

modules/main/src/main/java/com/annimon/ownlang/modules/jdbc/jdbc.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.annimon.ownlang.modules.jdbc;
22

33
import com.annimon.ownlang.exceptions.ArgumentsMismatchException;
4+
import com.annimon.ownlang.exceptions.OwnLangRuntimeException;
45
import com.annimon.ownlang.lib.*;
56
import com.annimon.ownlang.modules.Module;
67
import java.io.IOException;
@@ -99,7 +100,7 @@ private static com.annimon.ownlang.lib.Function getConnectionFunction(String con
99100
throw new ArgumentsMismatchException("Wrong number of arguments");
100101
}
101102
} catch (Exception ex) {
102-
throw new RuntimeException(ex);
103+
throw new OwnLangRuntimeException(ex);
103104
}
104105
};
105106
}
@@ -161,7 +162,7 @@ private Value createStatement(Value[] args) {
161162
throw new ArgumentsMismatchException("Wrong number of arguments");
162163
}
163164
} catch (SQLException sqlex) {
164-
throw new RuntimeException(sqlex);
165+
throw new OwnLangRuntimeException(sqlex);
165166
}
166167
}
167168

@@ -186,7 +187,7 @@ private Value prepareStatement(Value[] args) {
186187
throw new ArgumentsMismatchException("Wrong number of arguments");
187188
}
188189
} catch (SQLException sqlex) {
189-
throw new RuntimeException(sqlex);
190+
throw new OwnLangRuntimeException(sqlex);
190191
}
191192
}
192193

@@ -284,7 +285,7 @@ private void init() {
284285
try {
285286
return new URL(args[1].asString());
286287
} catch (IOException ioe) {
287-
throw new RuntimeException(ioe);
288+
throw new OwnLangRuntimeException(ioe);
288289
}
289290
}));
290291
}
@@ -298,7 +299,7 @@ private Value addBatch(Value[] args) {
298299
else statement.addBatch(args[0].asString());
299300
return NumberValue.ONE;
300301
} catch (SQLException sqlex) {
301-
throw new RuntimeException(sqlex);
302+
throw new OwnLangRuntimeException(sqlex);
302303
}
303304
}
304305

@@ -316,7 +317,7 @@ private Value execute(Value[] args) {
316317
(String[] columnNames) -> statement.execute(sql, columnNames));
317318
return NumberValue.fromBoolean(result);
318319
} catch (SQLException sqlex) {
319-
throw new RuntimeException(sqlex);
320+
throw new OwnLangRuntimeException(sqlex);
320321
}
321322
}
322323

@@ -345,7 +346,7 @@ private Value executeUpdate(Value[] args) {
345346
(String[] columnNames) -> statement.executeUpdate(sql, columnNames));
346347
return NumberValue.of(rowCount);
347348
} catch (SQLException sqlex) {
348-
throw new RuntimeException(sqlex);
349+
throw new OwnLangRuntimeException(sqlex);
349350
}
350351
}
351352

@@ -363,7 +364,7 @@ private Value executeLargeUpdate(Value[] args) {
363364
(String[] columnNames) -> statement.executeLargeUpdate(sql, columnNames));
364365
return NumberValue.of(rowCount);
365366
} catch (SQLException sqlex) {
366-
throw new RuntimeException(sqlex);
367+
throw new OwnLangRuntimeException(sqlex);
367368
}
368369
}
369370
}
@@ -463,7 +464,7 @@ private Value findColumn(Value[] args) {
463464
try {
464465
return NumberValue.of(rs.findColumn(args[0].asString()));
465466
} catch (SQLException sqlex) {
466-
throw new RuntimeException(sqlex);
467+
throw new OwnLangRuntimeException(sqlex);
467468
}
468469
}
469470

@@ -476,7 +477,7 @@ private Value updateNull(Value[] args) {
476477
rs.updateNull(args[0].asString());
477478
return NumberValue.ONE;
478479
} catch (SQLException sqlex) {
479-
throw new RuntimeException(sqlex);
480+
throw new OwnLangRuntimeException(sqlex);
480481
}
481482
}
482483
}
@@ -514,7 +515,7 @@ private static <T> T columnData(Value value, AutogeneratedKeys<T> autogeneratedK
514515
return columnNamesFunction.apply(columnNames);
515516

516517
} catch (SQLException sqlex) {
517-
throw new RuntimeException(sqlex);
518+
throw new OwnLangRuntimeException(sqlex);
518519
}
519520
}
520521

@@ -539,7 +540,7 @@ private static FunctionValue voidFunction(VoidResult result) {
539540
result.execute();
540541
return NumberValue.ONE;
541542
} catch (SQLException sqlex) {
542-
throw new RuntimeException(sqlex);
543+
throw new OwnLangRuntimeException(sqlex);
543544
}
544545
});
545546
}
@@ -551,7 +552,7 @@ private static FunctionValue voidIntFunction(VoidResultInt result) {
551552
result.execute(args[0].asInt());
552553
return NumberValue.ONE;
553554
} catch (SQLException sqlex) {
554-
throw new RuntimeException(sqlex);
555+
throw new OwnLangRuntimeException(sqlex);
555556
}
556557
});
557558
}
@@ -561,7 +562,7 @@ private static FunctionValue booleanFunction(BooleanResult result) {
561562
try {
562563
return NumberValue.fromBoolean(result.get());
563564
} catch (SQLException sqlex) {
564-
throw new RuntimeException(sqlex);
565+
throw new OwnLangRuntimeException(sqlex);
565566
}
566567
});
567568
}
@@ -571,7 +572,7 @@ private static Value intFunction(IntResult numberResult) {
571572
try {
572573
return NumberValue.of(numberResult.get());
573574
} catch (SQLException sqlex) {
574-
throw new RuntimeException(sqlex);
575+
throw new OwnLangRuntimeException(sqlex);
575576
}
576577
});
577578
}
@@ -581,7 +582,7 @@ private static Value stringFunction(StringResult stringResult) {
581582
try {
582583
return new StringValue(stringResult.get());
583584
} catch (SQLException sqlex) {
584-
throw new RuntimeException(sqlex);
585+
throw new OwnLangRuntimeException(sqlex);
585586
}
586587
});
587588
}
@@ -591,7 +592,7 @@ private static <T> Value objectFunction(ObjectResult<T> objectResult, Function<T
591592
try {
592593
return converter.apply(objectResult.get());
593594
} catch (SQLException sqlex) {
594-
throw new RuntimeException(sqlex);
595+
throw new OwnLangRuntimeException(sqlex);
595596
}
596597
});
597598
}
@@ -606,7 +607,7 @@ private static Value getBooleanResult(BooleanColumnResultInt numberResult, Boole
606607
}
607608
return NumberValue.fromBoolean(stringResult.get(args[0].asString()));
608609
} catch (SQLException sqlex) {
609-
throw new RuntimeException(sqlex);
610+
throw new OwnLangRuntimeException(sqlex);
610611
}
611612
});
612613
}
@@ -620,7 +621,7 @@ private static Value getNumberResult(NumberColumnResultInt numberResult, NumberC
620621
}
621622
return NumberValue.of(stringResult.get(args[0].asString()));
622623
} catch (SQLException sqlex) {
623-
throw new RuntimeException(sqlex);
624+
throw new OwnLangRuntimeException(sqlex);
624625
}
625626
});
626627
}
@@ -634,7 +635,7 @@ private static Value getStringResult(StringColumnResultInt numberResult, StringC
634635
}
635636
return new StringValue(stringResult.get(args[0].asString()));
636637
} catch (SQLException sqlex) {
637-
throw new RuntimeException(sqlex);
638+
throw new OwnLangRuntimeException(sqlex);
638639
}
639640
});
640641
}
@@ -649,7 +650,7 @@ private static <T> Value getObjectResult(ObjectColumnResultInt<T> numberResult,
649650
}
650651
return converter.apply(stringResult.get(args[0].asString()));
651652
} catch (SQLException sqlex) {
652-
throw new RuntimeException(sqlex);
653+
throw new OwnLangRuntimeException(sqlex);
653654
}
654655
});
655656
}
@@ -664,7 +665,7 @@ private static <T> Value getObjectResult(ObjectColumnResultInt<T> numberResult,
664665
}
665666
return converter.apply(stringResult.get(args[0].asString()), args);
666667
} catch (SQLException sqlex) {
667-
throw new RuntimeException(sqlex);
668+
throw new OwnLangRuntimeException(sqlex);
668669
}
669670
});
670671
}
@@ -676,7 +677,7 @@ private static <T> Value updateData(VoidResultObject<T> result, Function<Value[]
676677
result.execute(converter.apply(args));
677678
return NumberValue.ONE;
678679
} catch (SQLException sqlex) {
679-
throw new RuntimeException(sqlex);
680+
throw new OwnLangRuntimeException(sqlex);
680681
}
681682
});
682683
}
@@ -688,7 +689,7 @@ private static <T> Value updateData(VoidColumnResultIntObject<T> numberResult, F
688689
numberResult.execute(args[0].asInt(), converter.apply(args));
689690
return NumberValue.ONE;
690691
} catch (SQLException sqlex) {
691-
throw new RuntimeException(sqlex);
692+
throw new OwnLangRuntimeException(sqlex);
692693
}
693694
});
694695
}
@@ -705,7 +706,7 @@ private static <T> Value updateData(VoidColumnResultIntObject<T> numberResult, V
705706
}
706707
return NumberValue.ONE;
707708
} catch (SQLException sqlex) {
708-
throw new RuntimeException(sqlex);
709+
throw new OwnLangRuntimeException(sqlex);
709710
}
710711
});
711712
}
@@ -728,7 +729,7 @@ private static Value arrayToResultSetValue(Array array, Value[] args) {
728729
}
729730
return new ResultSetValue(result);
730731
} catch (SQLException sqlex) {
731-
throw new RuntimeException(sqlex);
732+
throw new OwnLangRuntimeException(sqlex);
732733
}
733734
}
734735

modules/main/src/main/java/com/annimon/ownlang/modules/json/json_decode.java

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

3+
import com.annimon.ownlang.exceptions.OwnLangRuntimeException;
34
import com.annimon.ownlang.lib.Arguments;
45
import com.annimon.ownlang.lib.Function;
56
import com.annimon.ownlang.lib.Value;
@@ -17,7 +18,7 @@ public Value execute(Value[] args) {
1718
final Object root = new JSONTokener(jsonRaw).nextValue();
1819
return ValueUtils.toValue(root);
1920
} catch (JSONException ex) {
20-
throw new RuntimeException("Error while parsing json", ex);
21+
throw new OwnLangRuntimeException("Error while parsing json", ex);
2122
}
2223
}
2324
}

modules/main/src/main/java/com/annimon/ownlang/modules/json/json_encode.java

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

3+
import com.annimon.ownlang.exceptions.OwnLangRuntimeException;
34
import com.annimon.ownlang.lib.Arguments;
45
import com.annimon.ownlang.lib.ArrayValue;
56
import com.annimon.ownlang.lib.Function;
@@ -36,7 +37,7 @@ public Value execute(Value[] args) {
3637
return new StringValue(jsonRaw);
3738

3839
} catch (JSONException ex) {
39-
throw new RuntimeException("Error while creating json", ex);
40+
throw new OwnLangRuntimeException("Error while creating json", ex);
4041
}
4142
}
4243

modules/main/src/main/java/com/annimon/ownlang/modules/okhttp/CallValue.java

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

3+
import com.annimon.ownlang.exceptions.OwnLangRuntimeException;
34
import com.annimon.ownlang.lib.Arguments;
45
import com.annimon.ownlang.lib.Converters;
56
import com.annimon.ownlang.lib.Function;
@@ -56,7 +57,7 @@ private Value execute(Value[] args) {
5657
try {
5758
return new ResponseValue(call.execute());
5859
} catch (IOException e) {
59-
throw new RuntimeException(e);
60+
throw new OwnLangRuntimeException(e);
6061
}
6162
}
6263
}

0 commit comments

Comments
 (0)