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

  • Home
  • SEARCH
  • 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 8134811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:10:42+00:00 2026-06-06T10:10:42+00:00

I have the following doubt concerning which exception to throw if list is empty

  • 0

I have the following doubt concerning which exception to throw if list is empty

public class XYZ implements Runnable {
    private List<File> contractFileList;

    @Override
    public void run() { 
        contractFileList = some method that will return the list;
        //now i want to check if returned contractFile is empty or not , if yes then raise the exception
        if (contractFileList.isEmpty()) {
            // throw new ?????
        }
    }
}

I am runing this code inside a batch, I want to throw some exception that will stop the batch execution.

  • 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-06T10:10:44+00:00Added an answer on June 6, 2026 at 10:10 am

    That looks like IllegalStateException to me.

    Signals that a method has been invoked at an illegal or inappropriate time.

    Basically your object is not in a valid state for run to be called.

    I wouldn’t create your own exception for this unless you expect it to be deliberately caught elsewhere. It sounds like this would only occur due to a programming error rather than an unexpected situation… in which case an unchecked exception is appropriate, and IllegalStateException describes the general nature of the problem quite clearly.

    You can put a detailed cause within the message of the exception (explaining that the “illegal state” was that the list was empty).

    I suggest you try to avoid creating a separate exception type for every little thing that can go wrong – unless you’re catching these exceptions separately, having different types doesn’t help; it only adds to the clutter. An exception which is of the right broad type but has a useful message provides just as much benefit without as much cognitive overhead.

    Note that you can’t use a checked exception if you’re implementing Runnable.run anyway, as that isn’t declared to throw any checked exceptions. You’d have to wrap it in an unchecked exception (e.g. RuntimeException) at which point there’s even less benefit.

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

Sidebar

Related Questions

I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have made the following code:- class A{ bool bFlag[2]; public: A(){ for(int i
I am newbie to iPhone programming. I have the following doubt which is stopping
I have the following code, could anyone please clarify my doubt below. public static
In following program . I have one doubt. I have declared one global variable
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
I have a doubt concerning declaring variables, their scope, and if their address could
I have a small doubt I have following code bool res= false; if(cond1) {

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.