coding style – Guard clauses in void methods

The consensus seems to be that it’s better to put an if statement guard clause at the top of a method rather than using an if else statement.

However, how can this be done with a void method and Console.WriteLine() to display an error? I would argue that example 2 is pretty ugly, especially if you have to validate multiple parameters and display separate errors when checking user input in a command line application for example.

I’m not an advanced programmer, but I’d argue the 1st example is more readable in this scenario. With that said, I can understand why people dislike complicated nested if statements.

1. If else statement

private static void ValidateInput(string() files, char() password)
{
    if (files != null)
    {
        if (password.Length > 0)
        {
            ... // 20 lines here
        }
        else
        {
            Console.WriteLine("Error: Please enter a password.");
        }
    }
    else
    {
        Console.WriteLine("Error: Please select a file.");
    }
}

2. If statement

private static void ValidateInput(string() files, char() password)
{
    if (files == null)
    {
        Console.WriteLine("Error: Please select a file.");
        return;
    }
    if (password.Length == 0)
    {
        Console.WriteLine("Error: Please select a file.");
        return;
    }
    ... // No indentation for the next 20 lines.
}