-
Notifications
You must be signed in to change notification settings - Fork 0
Description
If RandomOrgClient roc = RandomOrgClient.GetRandomOrgClient(YOUR_API_KEY_HERE); is executed without an active internet connection, the resulting exception is not handled by the surrounding try/catch block.
Instead of getting to the catch clause of my try/catch block:
try
{
var client = RandomOrgClient.GetRandomOrgClient(RANDOM_ORG_KEY);
var randomNumbers = client.GenerateIntegers(10, 1, 10, true);
}
catch (Exception ex)
{
// IT NEVER GETS HERE
}
In other words, exceptions triggered inside ThreadedRequestSending (the "core" part of the library) are not propagated back to the caller and they just make the applications crash.
How to reproduce:
- Implement a simple console application containing the code above
- Run it WITHOUT being connected to the Internet or just throw an exception from ThreadedRequestSending
The issue is likely caused by the fact that requested are sent in separate threads (ThreadedRequestSending), but this approach prevents proper handling of exceptions raised by the library. If that is the actual reason for this behaviour, I would suggest to use one of the following approaches to propagate the error back to the caller:
- Ashared data structure (e.g., ConcurrentQueue).
- Events or callbacks.
- Switch to Task and async/await for easier exception propagation.
