Skip to content

Commit 1a6e120

Browse files
committed
Вынесены общее исключение индекса и принадлежности строки
1 parent dddaa5e commit 1a6e120

File tree

7 files changed

+38
-22
lines changed

7 files changed

+38
-22
lines changed

src/OneScript.Core/Exceptions/RuntimeException.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,15 @@ public static RuntimeException IncorrectOffset()
182182
return new RuntimeException(
183183
"Неправильное смещение внутри коллекции",
184184
"Incorrect offset within collection");
185+
}
186+
187+
public static RuntimeException IndexOutOfRange()
188+
{
189+
return new RuntimeException(
190+
"Значение индекса выходит за пределы диапазона",
191+
"Index is out of range");
185192
}
193+
186194
#endregion
187195
}
188196
}

src/OneScript.StandardLibrary/Binary/BinaryDataBuffer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void WriteInt64(int position, BslValue value, BslValue byteOrder = null)
246246
private void WriteBitwiseOp(int position, BinaryDataBuffer buffer, int number, Func<byte, byte, byte> op)
247247
{
248248
if(position < 0)
249-
throw new IndexOutOfRangeException("Значение индекса выходит за границы диапазона");
249+
throw RuntimeException.IndexOutOfRange();
250250

251251
try
252252
{

src/OneScript.StandardLibrary/Collections/ArrayImpl.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void Add(IValue value = null)
9999
public void Insert(int index, IValue value = null)
100100
{
101101
if (index < 0)
102-
throw IndexOutOfBoundsException();
102+
throw RuntimeException.IndexOutOfRange();
103103

104104
if (index > _values.Count)
105105
Extend(index - _values.Count);
@@ -128,7 +128,7 @@ public IValue Find(IValue what)
128128
public void Remove(int index)
129129
{
130130
if (index < 0 || index >= _values.Count)
131-
throw IndexOutOfBoundsException();
131+
throw RuntimeException.IndexOutOfRange();
132132

133133
_values.RemoveAt(index);
134134
}
@@ -143,7 +143,7 @@ public int UpperBound()
143143
public IValue Get(int index)
144144
{
145145
if (index < 0 || index >= _values.Count)
146-
throw IndexOutOfBoundsException();
146+
throw RuntimeException.IndexOutOfRange();
147147

148148
return _values[index];
149149
}
@@ -152,7 +152,7 @@ public IValue Get(int index)
152152
public void Set(int index, IValue value)
153153
{
154154
if (index < 0 || index >= _values.Count)
155-
throw IndexOutOfBoundsException();
155+
throw RuntimeException.IndexOutOfRange();
156156

157157
_values[index] = value;
158158
}
@@ -234,10 +234,5 @@ public static ArrayImpl Constructor(FixedArrayImpl fixedArray)
234234
{
235235
return new ArrayImpl(fixedArray);
236236
}
237-
238-
private static RuntimeException IndexOutOfBoundsException()
239-
{
240-
return new RuntimeException("Значение индекса выходит за пределы диапазона");
241-
}
242237
}
243238
}

src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private int IndexByValue(BslValue item)
212212
}
213213

214214
if (index < 0 || index >= _items.Count())
215-
throw new RuntimeException("Значение индекса выходит за пределы диапазона");
215+
throw RuntimeException.IndexOutOfRange();
216216
}
217217

218218
return index;

src/OneScript.StandardLibrary/Collections/ValueTable/ValueTable.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private int IndexByValue(BslValue item)
504504
{
505505
index = IndexOf(row);
506506
if (index == -1)
507-
throw new RuntimeException("Строка не принадлежит таблице значений");
507+
throw ValueTableException.RowDoesntBelongTo();
508508
}
509509
else
510510
{
@@ -518,7 +518,7 @@ private int IndexByValue(BslValue item)
518518
}
519519

520520
if (index < 0 || index >= _rows.Count)
521-
throw new RuntimeException("Значение индекса выходит за пределы диапазона");
521+
throw RuntimeException.IndexOutOfRange();
522522
}
523523

524524
return index;
@@ -760,5 +760,24 @@ public IValue GetField(string name)
760760
{
761761
return Columns.FindColumnByName(name);
762762
}
763-
}
763+
}
764+
765+
public class ValueTableException : RuntimeException
766+
{
767+
public ValueTableException(BilingualString message, Exception innerException) : base(message,
768+
innerException)
769+
{
770+
}
771+
772+
public ValueTableException(BilingualString message) : base(message)
773+
{
774+
}
775+
776+
public static ValueTableException RowDoesntBelongTo()
777+
{
778+
return new ValueTableException(new BilingualString(
779+
"Строка не принадлежит таблице значений",
780+
"Row does not belong to table"));
781+
}
782+
}
764783
}

src/ScriptEngine/Machine/Contexts/StackTraceCollectionContext.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,9 @@ public override IValue GetIndexedValue(IValue index)
5353
var idx = (int)index.AsNumber();
5454

5555
if (idx < 0 || idx >= Count())
56-
throw IndexOutOfBoundsException();
56+
throw RuntimeException.IndexOutOfRange();
5757

5858
return _frames[idx];
5959
}
60-
61-
private static RuntimeException IndexOutOfBoundsException()
62-
{
63-
return new RuntimeException("Значение индекса выходит за пределы диапазона");
64-
}
65-
6660
}
6761
}

tests/binary-objects.os

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277
Буфер = ПолучитьБуферДвоичныхДанныхИзHexСтроки("01 02 03");
278278
Буфер.ЗаписатьПобитовоеИсключительноеИли(-1, ВторойБуфер, 3);
279279
Исключение
280-
юТест.ПроверитьВхождение(ОписаниеОшибки(), "Значение индекса выходит за границы диапазона");
280+
юТест.ПроверитьВхождение(ОписаниеОшибки(), "Значение индекса выходит за пределы диапазона");
281281
КонецПопытки;
282282

283283
КонецПроцедуры

0 commit comments

Comments
 (0)