Handling FTP exceptions like no internet etc Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Handling COM exceptions / busy codesKeeping UI responsive while performing long running taskEncapsulating common Try-Catch code. Is this a known pattern? Is it good or bad?Replace strings in a fileHandling an invalid SQL query exceptionC++ alternative to exceptionsSecuring User Credentials in CookiesGenerate and store passwords securelyURL decode a string but log an error after second exceptionIsDatabaseUp returns true or throws exception

Why are current probes so expensive?

NIntegrate on a solution of a matrix ODE

The bible of geometry: Is there a modern treatment of geometries from the most primitive to the most advanced?

Weaponising the Grasp-at-a-Distance spell

One-one communication

Pointing to problems without suggesting solutions

Centre cell contents vertically

How do you write "wild blueberries flavored"?

systemd and copy (/bin/cp): no such file or directory

Is a copyright notice with a non-existent name be invalid?

Find general formula for the terms

Marquee sign letters

latest version of QGIS fails to edit attribute table of GeoJSON file

Why can't fire hurt Daenerys but it did to Jon Snow in season 1?

Is it OK to use the testing sample to compare algorithms?

How does TikZ render an arc?

Order between one to one functions and their inverses

Understanding piped command in Gnu/Linux

When does a function NOT have an antiderivative?

The test team as an enemy of development? And how can this be avoided?

Is there any significance to the prison numbers of the Beagle Boys starting with 176-?

Why weren't discrete x86 CPUs ever used in game hardware?

By what mechanism was the 2017 UK General Election called?

What are some likely causes to domain member PC losing contact to domain controller?



Handling FTP exceptions like no internet etc



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Handling COM exceptions / busy codesKeeping UI responsive while performing long running taskEncapsulating common Try-Catch code. Is this a known pattern? Is it good or bad?Replace strings in a fileHandling an invalid SQL query exceptionC++ alternative to exceptionsSecuring User Credentials in CookiesGenerate and store passwords securelyURL decode a string but log an error after second exceptionIsDatabaseUp returns true or throws exception



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1












$begingroup$


I'm currently working in a project where the user needs to log in and after that i will check if the directory /cloud/user/Projects exists and if it doesn't i will create them.



The code works, however i would like to know if there is any better way of handleing exceptions,errors or if the internet is down while doing one of the steps.



I don't think that using try-catch blocks for each FTPCommand is the best way of doing it but i cannot find information about it.(I'm using FluentFTP library).



Also i'm using await and asynchronous methods because i do not want to freeze the UI (WPF).



 var ftp = StoryManager.MainWindow.FtpClient;

ContentGrid.Opacity = 0;
LoadingIndicator.Opacity = 1;

if (UsernameTextBox.Text.Equals("") || PasswordTextBox.Password.ToString().Equals(""))


MessageBox.Show("Please, enter your credentials");
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
return;



if ((Properties.Settings.Default.LoggedUser = await Rest.LoginAsync(UsernameTextBox.Text.ToLower(), PasswordTextBox.Password.ToString())) != null)

Properties.Settings.Default.KeepLogged = (bool)KeepLogged.IsChecked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload();
string userDir = "/cloud/" + Properties.Settings.Default.LoggedUser.UserName;

try

bool userDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir);
bool projectsDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir + "/Projects");
bool fileExist = StoryManager.MainWindow.FtpClient.FileExists("log.txt");

if (userDirExist)

try

await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);


if (!projectsDirExist)

try

await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);




else

try

await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);



if (!fileExist)

var tempPath = Path.GetTempPath();
var textFile = "##### Log File #####";
textFile.AddLine(DateTime.Now.ToString());
File.WriteAllText(tempPath + "log.txt", textFile);
await StoryManager.MainWindow.FtpClient.UploadFileAsync(tempPath + "log.txt", "log.txt");
File.Delete(tempPath + "log.txt");


StoryManager.Add(new WelcomeScreen());



catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);



else

ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;

}


Any tips/recommendations for better security, performance and error handleing for this method or for FTP management in general?



Edit 1



The Rest.LoginAsync method implementation is



 public static async Task<User> LoginAsync(string usernameValue, string passwordValue)


try

var result = await "https://foo.com/bar"
.PostUrlEncodedAsync(new

username = usernameValue,
password = passwordValue
).ReceiveString();

var fields = result.Split(';');

switch (result)

case "-1":
MessageBox.Show("User/Password error");
break;
case "-2":
MessageBox.Show("User/Password error");
break;
case "-3":
MessageBox.Show("No License");
break;
case "-4":
MessageBox.Show("Connection error");
break;
default:
break;


User loggedUser = new User

IdUser = int.Parse(fields[0]),
UserName = fields[1],
MembershipStatus = fields[2],
Name = fields[3]
;

return loggedUser;


catch (Exception ex)


Console.WriteLine(ex.ToString());


return null;




The rest of the operations are from C#, WPF or FluentFTP (CreateDirectory, UploadFile...)










share|improve this question











$endgroup$




bumped to the homepage by Community 8 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 2




    $begingroup$
    It'd be better if you posted the complete method, not just a snippet.
    $endgroup$
    – t3chb0t
    Feb 21 '18 at 9:36










  • $begingroup$
    I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
    $endgroup$
    – ODB8
    Feb 21 '18 at 10:35


















1












$begingroup$


I'm currently working in a project where the user needs to log in and after that i will check if the directory /cloud/user/Projects exists and if it doesn't i will create them.



The code works, however i would like to know if there is any better way of handleing exceptions,errors or if the internet is down while doing one of the steps.



I don't think that using try-catch blocks for each FTPCommand is the best way of doing it but i cannot find information about it.(I'm using FluentFTP library).



Also i'm using await and asynchronous methods because i do not want to freeze the UI (WPF).



 var ftp = StoryManager.MainWindow.FtpClient;

ContentGrid.Opacity = 0;
LoadingIndicator.Opacity = 1;

if (UsernameTextBox.Text.Equals("") || PasswordTextBox.Password.ToString().Equals(""))


MessageBox.Show("Please, enter your credentials");
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
return;



if ((Properties.Settings.Default.LoggedUser = await Rest.LoginAsync(UsernameTextBox.Text.ToLower(), PasswordTextBox.Password.ToString())) != null)

Properties.Settings.Default.KeepLogged = (bool)KeepLogged.IsChecked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload();
string userDir = "/cloud/" + Properties.Settings.Default.LoggedUser.UserName;

try

bool userDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir);
bool projectsDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir + "/Projects");
bool fileExist = StoryManager.MainWindow.FtpClient.FileExists("log.txt");

if (userDirExist)

try

await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);


if (!projectsDirExist)

try

await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);




else

try

await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);



if (!fileExist)

var tempPath = Path.GetTempPath();
var textFile = "##### Log File #####";
textFile.AddLine(DateTime.Now.ToString());
File.WriteAllText(tempPath + "log.txt", textFile);
await StoryManager.MainWindow.FtpClient.UploadFileAsync(tempPath + "log.txt", "log.txt");
File.Delete(tempPath + "log.txt");


StoryManager.Add(new WelcomeScreen());



catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);



else

ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;

}


Any tips/recommendations for better security, performance and error handleing for this method or for FTP management in general?



Edit 1



The Rest.LoginAsync method implementation is



 public static async Task<User> LoginAsync(string usernameValue, string passwordValue)


try

var result = await "https://foo.com/bar"
.PostUrlEncodedAsync(new

username = usernameValue,
password = passwordValue
).ReceiveString();

var fields = result.Split(';');

switch (result)

case "-1":
MessageBox.Show("User/Password error");
break;
case "-2":
MessageBox.Show("User/Password error");
break;
case "-3":
MessageBox.Show("No License");
break;
case "-4":
MessageBox.Show("Connection error");
break;
default:
break;


User loggedUser = new User

IdUser = int.Parse(fields[0]),
UserName = fields[1],
MembershipStatus = fields[2],
Name = fields[3]
;

return loggedUser;


catch (Exception ex)


Console.WriteLine(ex.ToString());


return null;




The rest of the operations are from C#, WPF or FluentFTP (CreateDirectory, UploadFile...)










share|improve this question











$endgroup$




bumped to the homepage by Community 8 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 2




    $begingroup$
    It'd be better if you posted the complete method, not just a snippet.
    $endgroup$
    – t3chb0t
    Feb 21 '18 at 9:36










  • $begingroup$
    I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
    $endgroup$
    – ODB8
    Feb 21 '18 at 10:35














1












1








1





$begingroup$


I'm currently working in a project where the user needs to log in and after that i will check if the directory /cloud/user/Projects exists and if it doesn't i will create them.



The code works, however i would like to know if there is any better way of handleing exceptions,errors or if the internet is down while doing one of the steps.



I don't think that using try-catch blocks for each FTPCommand is the best way of doing it but i cannot find information about it.(I'm using FluentFTP library).



Also i'm using await and asynchronous methods because i do not want to freeze the UI (WPF).



 var ftp = StoryManager.MainWindow.FtpClient;

ContentGrid.Opacity = 0;
LoadingIndicator.Opacity = 1;

if (UsernameTextBox.Text.Equals("") || PasswordTextBox.Password.ToString().Equals(""))


MessageBox.Show("Please, enter your credentials");
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
return;



if ((Properties.Settings.Default.LoggedUser = await Rest.LoginAsync(UsernameTextBox.Text.ToLower(), PasswordTextBox.Password.ToString())) != null)

Properties.Settings.Default.KeepLogged = (bool)KeepLogged.IsChecked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload();
string userDir = "/cloud/" + Properties.Settings.Default.LoggedUser.UserName;

try

bool userDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir);
bool projectsDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir + "/Projects");
bool fileExist = StoryManager.MainWindow.FtpClient.FileExists("log.txt");

if (userDirExist)

try

await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);


if (!projectsDirExist)

try

await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);




else

try

await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);



if (!fileExist)

var tempPath = Path.GetTempPath();
var textFile = "##### Log File #####";
textFile.AddLine(DateTime.Now.ToString());
File.WriteAllText(tempPath + "log.txt", textFile);
await StoryManager.MainWindow.FtpClient.UploadFileAsync(tempPath + "log.txt", "log.txt");
File.Delete(tempPath + "log.txt");


StoryManager.Add(new WelcomeScreen());



catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);



else

ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;

}


Any tips/recommendations for better security, performance and error handleing for this method or for FTP management in general?



Edit 1



The Rest.LoginAsync method implementation is



 public static async Task<User> LoginAsync(string usernameValue, string passwordValue)


try

var result = await "https://foo.com/bar"
.PostUrlEncodedAsync(new

username = usernameValue,
password = passwordValue
).ReceiveString();

var fields = result.Split(';');

switch (result)

case "-1":
MessageBox.Show("User/Password error");
break;
case "-2":
MessageBox.Show("User/Password error");
break;
case "-3":
MessageBox.Show("No License");
break;
case "-4":
MessageBox.Show("Connection error");
break;
default:
break;


User loggedUser = new User

IdUser = int.Parse(fields[0]),
UserName = fields[1],
MembershipStatus = fields[2],
Name = fields[3]
;

return loggedUser;


catch (Exception ex)


Console.WriteLine(ex.ToString());


return null;




The rest of the operations are from C#, WPF or FluentFTP (CreateDirectory, UploadFile...)










share|improve this question











$endgroup$




I'm currently working in a project where the user needs to log in and after that i will check if the directory /cloud/user/Projects exists and if it doesn't i will create them.



The code works, however i would like to know if there is any better way of handleing exceptions,errors or if the internet is down while doing one of the steps.



I don't think that using try-catch blocks for each FTPCommand is the best way of doing it but i cannot find information about it.(I'm using FluentFTP library).



Also i'm using await and asynchronous methods because i do not want to freeze the UI (WPF).



 var ftp = StoryManager.MainWindow.FtpClient;

ContentGrid.Opacity = 0;
LoadingIndicator.Opacity = 1;

if (UsernameTextBox.Text.Equals("") || PasswordTextBox.Password.ToString().Equals(""))


MessageBox.Show("Please, enter your credentials");
ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;
return;



if ((Properties.Settings.Default.LoggedUser = await Rest.LoginAsync(UsernameTextBox.Text.ToLower(), PasswordTextBox.Password.ToString())) != null)

Properties.Settings.Default.KeepLogged = (bool)KeepLogged.IsChecked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload();
string userDir = "/cloud/" + Properties.Settings.Default.LoggedUser.UserName;

try

bool userDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir);
bool projectsDirExist = StoryManager.MainWindow.FtpClient.DirectoryExists(userDir + "/Projects");
bool fileExist = StoryManager.MainWindow.FtpClient.FileExists("log.txt");

if (userDirExist)

try

await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);


if (!projectsDirExist)

try

await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);




else

try

await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.SetWorkingDirectoryAsync(userDir);
await StoryManager.MainWindow.FtpClient.CreateDirectoryAsync(userDir + "/Projects");

catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);



if (!fileExist)

var tempPath = Path.GetTempPath();
var textFile = "##### Log File #####";
textFile.AddLine(DateTime.Now.ToString());
File.WriteAllText(tempPath + "log.txt", textFile);
await StoryManager.MainWindow.FtpClient.UploadFileAsync(tempPath + "log.txt", "log.txt");
File.Delete(tempPath + "log.txt");


StoryManager.Add(new WelcomeScreen());



catch (Exception ex)

System.Windows.Forms.MessageBox.Show("An error ocurred please try again " + ex.Message);



else

ContentGrid.Opacity = 1;
LoadingIndicator.Opacity = 0;

}


Any tips/recommendations for better security, performance and error handleing for this method or for FTP management in general?



Edit 1



The Rest.LoginAsync method implementation is



 public static async Task<User> LoginAsync(string usernameValue, string passwordValue)


try

var result = await "https://foo.com/bar"
.PostUrlEncodedAsync(new

username = usernameValue,
password = passwordValue
).ReceiveString();

var fields = result.Split(';');

switch (result)

case "-1":
MessageBox.Show("User/Password error");
break;
case "-2":
MessageBox.Show("User/Password error");
break;
case "-3":
MessageBox.Show("No License");
break;
case "-4":
MessageBox.Show("Connection error");
break;
default:
break;


User loggedUser = new User

IdUser = int.Parse(fields[0]),
UserName = fields[1],
MembershipStatus = fields[2],
Name = fields[3]
;

return loggedUser;


catch (Exception ex)


Console.WriteLine(ex.ToString());


return null;




The rest of the operations are from C#, WPF or FluentFTP (CreateDirectory, UploadFile...)







c# security error-handling wpf ftp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 21 '18 at 10:34







ODB8

















asked Feb 21 '18 at 9:24









ODB8ODB8

112




112





bumped to the homepage by Community 8 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 8 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.









  • 2




    $begingroup$
    It'd be better if you posted the complete method, not just a snippet.
    $endgroup$
    – t3chb0t
    Feb 21 '18 at 9:36










  • $begingroup$
    I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
    $endgroup$
    – ODB8
    Feb 21 '18 at 10:35













  • 2




    $begingroup$
    It'd be better if you posted the complete method, not just a snippet.
    $endgroup$
    – t3chb0t
    Feb 21 '18 at 9:36










  • $begingroup$
    I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
    $endgroup$
    – ODB8
    Feb 21 '18 at 10:35








2




2




$begingroup$
It'd be better if you posted the complete method, not just a snippet.
$endgroup$
– t3chb0t
Feb 21 '18 at 9:36




$begingroup$
It'd be better if you posted the complete method, not just a snippet.
$endgroup$
– t3chb0t
Feb 21 '18 at 9:36












$begingroup$
I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
$endgroup$
– ODB8
Feb 21 '18 at 10:35





$begingroup$
I updated my post with the other method code, however, i do not know how the FTP library is implemented or how C# or WPF implement there methods...Do you need anything else?
$endgroup$
– ODB8
Feb 21 '18 at 10:35











1 Answer
1






active

oldest

votes


















0












$begingroup$

  • I would add a variable var ftpClient = StoryManager.MainWindow.FtpClient; to shorten the calls to FtpClient a bit

  • You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)





share|improve this answer









$endgroup$













    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "196"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188006%2fhandling-ftp-exceptions-like-no-internet-etc%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0












    $begingroup$

    • I would add a variable var ftpClient = StoryManager.MainWindow.FtpClient; to shorten the calls to FtpClient a bit

    • You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)





    share|improve this answer









    $endgroup$

















      0












      $begingroup$

      • I would add a variable var ftpClient = StoryManager.MainWindow.FtpClient; to shorten the calls to FtpClient a bit

      • You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)





      share|improve this answer









      $endgroup$















        0












        0








        0





        $begingroup$

        • I would add a variable var ftpClient = StoryManager.MainWindow.FtpClient; to shorten the calls to FtpClient a bit

        • You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)





        share|improve this answer









        $endgroup$



        • I would add a variable var ftpClient = StoryManager.MainWindow.FtpClient; to shorten the calls to FtpClient a bit

        • You catch exceptions several times, but handle them equally. And also continue after an error. I would make a single try..catch block around everything. So the exception handling code is not duplicated and the following actions don't get executed. (Why try to add a project dir to user dir project dir does not exist yet?)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 25 '18 at 17:01









        Markus MeyerMarkus Meyer

        211




        211



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Code Review Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188006%2fhandling-ftp-exceptions-like-no-internet-etc%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

            格濟夫卡 參考資料 导航菜单51°3′40″N 34°2′21″E / 51.06111°N 34.03917°E / 51.06111; 34.03917ГезівкаПогода в селі 编辑或修订