Ir al contenido

Embed inner exception (ARCH403)

Esta página aún no está disponible en tu idioma.

Key dotnet.exception.embed-inner-exception · Severity warning · Category exception

When throwing a new exception inside a catch block, pass the caught exception as the innerException. Otherwise the original stack trace and error context are lost.

try
{
_repository.Save(order);
}
catch (DbException ex)
{
throw new OrderSaveException("Could not save order");
}
try
{
_repository.Save(order);
}
catch (DbException ex)
{
throw new OrderSaveException("Could not save order", ex);
}

Pass the caught exception as the innerException to the new exception’s constructor. If needed, suppress the rule per project/workspace via except/ignore.