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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:00:54+00:00 2026-05-12T08:00:54+00:00

I want the api of my module to only throw MyPackageSpecificException whenever anything goes

  • 0

I want the api of my module to only throw MyPackageSpecificException whenever anything goes wrong and the module unable to perform its task. (The original exception will be given as the cause of the MyPackageSpecificException).

Now, for one constructor I needed an URL as a parameter to locate a resource. I would also like to make an alternative constructor to which a String representation of the URL can be given:

public MyClass(String urlString) throws MalformedURLException{
    this(new URL(urlString));
}

As the URL constructor throws MalformedURLException, I want to wrap it into a MyPackageSpecificException by doing:

public MyClass(String urlString) throws MyPackageSpecificException{
    try{
        this(new URL(urlString));
    } catch (MalformedURLException e){
        throw new MyPackageSpecificException(e);
    }
}

But, the above is not valid, since the super() or this() constructor call must occur on the first line of the constructor.

The same problem applies if the super() or this() constructor throws an exception which I want to wrap into something else.

How should I solve this? Or is what I am trying to do bad practice?

  • 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-12T08:00:54+00:00Added an answer on May 12, 2026 at 8:00 am

    Try the following:

    public class MyClass
    {
      private URL url;
    
      public MyClass(URL url)
      {
        this.url = url;
      }
    
      public MyClass(String urlString) throws MyPackageSpecificException
      { 
        this(toURL(urlString));
      }
    
      private static URL toURL(String urlString) throws MyPackageSpecificException
      {
        try
        {
          return new URL(urlString));
        } 
        catch (MalformedURLException e)
        {
            throw new MyPackageSpecificException(e);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to build an API service using Django. A basic workflow goes like
I'm using LIFT to serve a RESTful API, and I want this API to
I want to measure API evolution for a given Java project, in particular new/renamed
i have a backbone.js api i want to use in an ExtJS app. Extjs
Hi i am new in using facebook api i want to get the friends
I want to learn windows API and PInvoke methods just like MesseageBeep in User32.dll.
I want to access Android API classes outside an Android project . For example
I want to know the differences of File API in html5 and previous version.
I want to create a rest api using reasteasy and jax-rs in spring. to
I want to use the Criteria API to select entities by taking the input

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.