.inquisitiverabbit
.inquisitiverabbit
CC#
Created by .inquisitiverabbit on 3/31/2023 in #help
✅ Design of error handling for database calls (dapper, .net core)
Hello, Writing an app that uses DB calls (from dapper) and wondering how most people like to see error handling for these. Currently I have:
DailyLogBeam? dailyLogInfo = null;
try
{
dailyLogInfo = await _db.GetOne<DailyLogBeam, dynamic, SqlConnection>(sql, new { shift = shift.StartTime }, "Meltcast");
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to fetch log info!");
}

if (dailyLogInfo is null)
{
//initializing empty db result
}

// Continued execution with db results
DailyLogBeam? dailyLogInfo = null;
try
{
dailyLogInfo = await _db.GetOne<DailyLogBeam, dynamic, SqlConnection>(sql, new { shift = shift.StartTime }, "Meltcast");
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to fetch log info!");
}

if (dailyLogInfo is null)
{
//initializing empty db result
}

// Continued execution with db results
3 replies