Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8087883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:55:19+00:00 2026-06-05T18:55:19+00:00

I am trying to make a monitoring application for a FTP server using FTP4J

  • 0

I am trying to make a monitoring application for a FTP server using FTP4J(referred to as client in the code example).

It connects to a FTP, logs in, creates a file locally, uploads file, downloads file, validates the files are the same, cleans up files on ftp and locally and disconnects.

All this is already made but my question is how do I best log what has happened and break when an error is detected?

The simple solution I could think of was to make a Boolean that shows if previous steps where successful and only do next step if they where.

StringBuilder sb = new StringBuilder();
boolean noError = true;
// Connect to FTP
try {
    client.connect(hostname, port);
} catch (Exception e) {
    noError = false;
    sb.append("failed to connect<br>");
}

//Logging in to FTP
if(noError) {
    try {
        client.login(username, password);

    } catch (Exception e) {
        noError = false;
        sb.append("failed to login<br>");
    }
}
...
// Close connection
if(client.isConnected()) {
    try {
        client.disconnect(true);
    } catch (Exception e) {
        sb.append("failed to disconnect<br>");
    }
}

another solution I could think of was nested try/catch but that looked even worse, is there a better way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:55:21+00:00Added an answer on June 5, 2026 at 6:55 pm

    The solution is simple: don’t catch the exception. As soon as an exception is thrown and is not caught, the whole process will stop. Or catch it but transform it into your own exception with the appropriate error message, and throw this exception.

    Side note: you should use a boolean and not a Boolean to store a non-nullable boolean value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying make a JSON call to a server using HttpClient API. The
I'm trying make some stuff in jQuery using ASP.NET. But the ID from runat=server
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to make this simple applet - the first part just creates a simple
I am trying make such application which speak automatically when the image loaded it
I am trying make a segue call in a tableview , but the application
I'm trying make a <dl> to define the icons I am using on the
I am trying to make a parental control program that will prevent using the
I am trying make a request and get response from server. Here is my
in my application I am trying make a requst but i have received an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.