I have a convertation method called ToExceptionDto

private ToExceptionDto(Exception ex)
{
   return new ExceptionDto(ex.Message, ex.StackTrace)
}

I have two options
Option 1. Check for null at the beginning of the method:

private ToExceptionDto(Exception ex)
{
   if(ex == null)
   {
      return ExceptionDto.Empty();
   }
   return new ExceptionDto(ex.Message, ex.StackTrace)
}

And option 2. Check for null in a caller method:

private void Consumer()
{
     var convertedOne = ex == null ? ExceptionDto.Empty() : ToExceptionDto(ex);
}

Which of these two options is a better practice?

I personally prefer option 2

New contributor

Sergey Dev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1