Skip to content

Commit da97c03

Browse files
committed
[C#] Catch more specific exception when getting bytes from an encoding.
1 parent 2e02a19 commit da97c03

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

csharp/sbe-samples-car/CarExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ static CarExample()
8080
ManufacturerCode = Engine.ManufacturerCodeResolvedCharacterEncoding.GetBytes("123");
8181
ActivationCode = Car.ActivationCodeResolvedCharacterEncoding.GetBytes("abcdef");
8282
}
83-
catch (Exception ex)
83+
catch (EncoderFallbackException ex)
8484
{
85-
throw new Exception("An error occured while reading encodings", ex);
85+
throw new Exception("An error occurred while reading encodings", ex);
8686
}
8787
}
8888

csharp/sbe-samples-extension/ExtensionExample.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ static ExtensionExample()
100100
Model = Encoding.GetEncoding(Car.ModelCharacterEncoding).GetBytes("Civic VTi");
101101
ActivationCode = Encoding.GetEncoding(Car.ActivationCodeCharacterEncoding).GetBytes("abcdef");
102102
}
103-
catch (Exception ex)
103+
catch (EncoderFallbackException ex)
104104
{
105-
throw new Exception("An error occured while reading encodings", ex);
105+
throw new Exception("An error occurred while reading encodings", ex);
106106
}
107107
}
108108

109109

110-
111110
public static int Encode(Car car, DirectBuffer directBuffer, int bufferOffset)
112111
{
113112
const int srcOffset = 0;
@@ -312,7 +311,7 @@ static ExtensionExample()
312311
Model = Encoding.GetEncoding(Car.ModelCharacterEncoding).GetBytes("Civic VTi");
313312
ActivationCode = Encoding.GetEncoding(Car.ActivationCodeCharacterEncoding).GetBytes("abcdef");
314313
}
315-
catch (Exception ex)
314+
catch (EncoderFallbackException ex)
316315
{
317316
throw new Exception("An error occurred while reading encodings", ex);
318317
}
@@ -390,7 +389,7 @@ public static int Encode(Car car, DirectBuffer directBuffer, int bufferOffset)
390389

391390
// we have written all the constant length fields, now we can write the repeatable groups
392391

393-
var fuelFigures = car.FuelFiguresCount(3); // we specify that we are going to write 3 FueldFigures (the API is not very .NET friendly yet, we will address that)
392+
var fuelFigures = car.FuelFiguresCount(3); // we specify that we are going to write 3 FuelFigures (the API is not very .NET friendly yet, we will address that)
394393
fuelFigures.Next(); // move to the first element
395394
fuelFigures.Speed = 30;
396395
fuelFigures.Mpg = 35.9f;

0 commit comments

Comments
 (0)