Private/ErrorHandlingFunctions.ps1

function RegisterException
{
    if (![String]::IsNullOrWhiteSpace($systemLog)) 
    {
        WriteLog -Path $systemLog -Message "ERROR: Error occurred" -RedirectStream $true
        Write-Warning "WARNING: For details examine '$systemLog'" *>&1
    }
    else 
    {
        Write-Warning "ERROR: Error occurred" *>&1
    }
     
    $logMessage = $_.Exception | Format-List -Force | Out-String
    WriteLog -Path $systemLog -Message "VERBOSE_ERROR: $logMessage"
}