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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:08:02+00:00 2026-06-11T00:08:02+00:00

I have a separate JAR library with a collection of methods that throw custom

  • 0

I have a separate JAR library with a collection of methods that throw custom exceptions, for example:

public String methodName() throws CustomException {
    // code here
}

I then add the JAR to the classpath and reference the library method within a try statement in source code:

try {
    DemoClass demoClass = new DemoClass ();
    demoClass.methodName() // this should throw a CustomException if something occurs
} catch (CustomException e) {
    // something here
}

The above code snippet keeps returning the following compilation error:

CustomException is never thrown in the body of corresponding try statement

If the method is in the local context (not packaged in a JAR) the code works.. So my question, is it possible to “throw” custom exceptions from JAR libraries?

  • 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-11T00:08:04+00:00Added an answer on June 11, 2026 at 12:08 am

    It doesn’t really matter whether the your class is in a jar or in the local context, it can always throw exceptions. You should check if you are using the class and calling the method that you intend to and not some other class and some other method with same name.

    My hunch is something like ParseException which is in both java.text.ParseException and in org.apache.commons.cli.ParseException and when demoClass.methodName() actually throws the former, you would have imported the latter in your code and trying to catch it and that is what the compiler is complaining about. You may want to check all the locations where the CustomException is present and you are trying to catch the right one.

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

Sidebar

Related Questions

I have multiple, separate leiningen projects that ostensibly could depend on one-another. Example: ~/projects/mywebapp
I have a website that is mirrored cross two sub-domains. So I have separate
I am writing a custom library. It's build into a .jar archive. I am
I have a locally-created jar file containing hibernate-annotated entities. I also have a separate
I have a project that only needs to take a proguard-constructed jar file, which
I'm trying to separate a Java Library, that is used by multiple Android services,
Do I need to have separate/multiple workers to run multiple websites (each with a
What's the best way to have separate CSS for IE and other browsers? I'm
In my ASP.NET application I have separate projects for the Data, Business and UI
I have a database containing user details. I don't have separate columns for 'firstname'

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.