Skip to content

Error Handling Examples

Documentation in Progress

This documentation is currently being developed. The comprehensive exception handling system is implemented in Issue 002-105.

Status: ✅ Core functionality complete, 📝 Documentation in progress
Expected completion: After Issue 002-106 (Cross-Component Integration Layer)

Coming Soon

This page will provide practical examples for robust error handling in Belay.NET applications, including:

  • Device Connection Errors: Handling serial port issues and device disconnects
  • Execution Errors: Managing Python syntax errors and runtime exceptions
  • Timeout Handling: Graceful timeout management and retry strategies
  • Session Recovery: Automatic reconnection and state restoration
  • Custom Exception Types: Working with BelayException hierarchy
  • Logging Integration: Structured error logging with Microsoft.Extensions.Logging
  • Production Patterns: Enterprise-grade error handling strategies

Quick Preview

csharp
// Example of what's coming - robust device operation with error handling
public class RobustDevice : Device
{
    [Task(RetryAttempts = 3, TimeoutMs = 10000)]
    public async Task<float> GetCriticalSensorDataAsync()
    {
        try
        {
            return await ExecuteAsync<float>("sensor.read_critical_data()");
        }
        catch (DeviceExecutionException ex) when (ex.ErrorType == "sensor_error")
        {
            // Handle sensor-specific errors
            await ExecuteAsync("sensor.reset()");
            throw;
        }
        catch (DeviceConnectionException ex)
        {
            // Handle connection issues with automatic retry
            await ReconnectAsync();
            throw;
        }
    }
}

Need help now? Check our GitHub Discussions or review the exception handling guide.

Released under the Apache License 2.0.