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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:27:57+00:00 2026-05-25T13:27:57+00:00

I have the following code: public boolean perform(CronJob job) final Date lastQueryDateTime = new

  • 0

I have the following code:

public boolean perform(CronJob job)
   final Date lastQueryDateTime = new Date();
   QueryMode queryMode = job.getQueryModeEnum();
   try {
      if (queryMode.getCode().equals("FULL")) 
      {
         calculateCoverage();    

      } else if (queryMode.getCode().equals("INCREMENTAL")) 
      {
          calculateCoverage();
      }        
       job.setLastQueryDate(lastQueryDateTime);
       job.save(job);

       return true;

      } catch (Exception e) {
       LOG.error("Error while calculating the coverage for products.", e);
       return false;
      }
}

private void calculateCoverage()
{

// Some Logic

}

I got in doubt if there is actually too much logic to be handled in between and if the try/catch scope is to wide. Is there a better approach to do this??. I would liket handle the try/catch within calculateCoverage but in that case I will need to pass job as an argurment to calculateCoverage and I think is not that clean.. Any suggestions?

thank you!

  • 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-05-25T13:27:57+00:00Added an answer on May 25, 2026 at 1:27 pm

    It looks like this is a Quartz job (or something like it), which isn’t supposed to allow an exception to be thrown.

    So it’s not that you expect a particular method to throw a particular type of exception (in which case you would want to reduce the scope to that method call). Rather, you want to ensure that if anything inside this method goes awry, you won’t put your Cron Job into an error state.

    Since the sole purpose of the try/catch in this case is to log any exceptions that are thrown, and you’re not planning to handle them in any special way, I think it’s perfectly reasonable to have the block encompass the entire contents of the method.

    Pay attention to the overall logic, though. Currently an exception in calculating coverage will result in the job not being set to run again. If you want the job to run later even if it fails now, you may want to have a try/finally block in there.

    try {
        final Date lastQueryDateTime = new Date();
        QueryMode queryMode = job.getQueryModeEnum();
        String code = queryMode.getCode();
        try{
            if (code.equals("FULL") || code.equals("INCREMENTAL")) 
            {
                calculateCoverage();
            }   
        } finally {
            job.setLastQueryDate(lastQueryDateTime);
            job.save(job);
        }
        return true;
    } catch (Exception e) {
        LOG.error("Error while calculating the coverage for products.", e);
        return false;
    }
    

    This will still cause any exception in the method to be caught and logged, but if the error happens while calculating coverage, you’ll still try to set the job to run again.

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

Sidebar

Related Questions

I have the following code in my app: public static final boolean DEBUG =
I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: Public Class Form1 Private Function Step1_Execute() As Boolean Return
I have the following code: public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[]
I have the following code in an equals method. public boolean equals(Object o){ if
Hi i have the following code: public List<Person> findAll() { List<Person> copy = new
I have the following code in a java Web Service: public boolean makeFile(String fileName,
I have a following pseudo-code. public boolean onContextItemSelected(MenuItem aItem) { switch(aItem.getItemId()) { case A:
In my application I have the following code... public Boolean SaveUserInformation(UserInfoDTO UserInformation) { return
I have the following code public class Test { Lock lock = new ReentrantLock();

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.