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 8999949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:14:53+00:00 2026-06-16T00:14:53+00:00

Let’s say I have the following code: void validate(File f) //or boolean????? { …

  • 0

Let’s say I have the following code:

void validate(File f) //or boolean?????
{
  ...
  try
  {
    //try to validate xml file
  }
  catch (Exception e)
  {
  }
}

...

try
{

  validate(xml_file); //validates XML file
  move(xml_file, valid_folder); //moves valid XML file to valid_folder
}
catch (Exception e)
{
  move(xml_file, error_folder); //moves invalid XML file to error_folder
}

...

Should my validate() function be boolean and I should check whether file is valid XML file or not or catching will do it for me?

  • 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-16T00:14:53+00:00Added an answer on June 16, 2026 at 12:14 am

    One problem you might want to think about is the single responsibility principle: a method should do one thing well.

    Your validate method is doing at least three things:

    1. Reading XML from a file
    2. Validating that XML in some unspecified way
    3. Moving the file to one folder or another, depending on outcome

    Perhaps you’ll have an easier time if you break these up.

    What if someone wants to validate XML without moving the file? Your method can’t be called in that case.

    Even validating is questionable. If you check against a schema you’ll throw an exception on the first issue. Would users want to know ALL the problems at once? If yes, you’ll have to walk the tree and find all the errors yourself.

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

Sidebar

Related Questions

Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say I have a file foo.py, and within the file I want to
let's say.. I have the following java bean. Case1: (Student Bean) Integer id; String
Let's say, I have an application that access(read/write) the file system(files inside application), Active
let's say I have the following string: string s = A B C D
Let's say I have the following entity: public class Store { public List<Product> Products
Let's say I have a domain object with the following field: private Map<StatType, Double>
Let's say I have 2 functions: void function1(int *ptr) { printf(%d, *ptr); } and
Let's say I have the following two lists of tuples myList = [(1, 7),
Let's assume I have the following typedef: typedef void (^myBlock)(id); And I have some

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.