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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:45:41+00:00 2026-06-14T12:45:41+00:00

I got a method that throw an exception if I try to insert an

  • 0

I got a method that throw an exception if I try to insert an existing object in DB.

 public void addInDB() throws Exception {
    if (isInBase()){
          throw new Exception ("[ReqFamily->addInDB] requirment already in base");
    }
    int idParent = m_parent.getIdBdd();

    idBdd = pSQLRequirement.add(name, description, 0, idParent,   
    ReqPlugin.getProjectRef().getIdBdd(), 100);
}

So when the exception is thrown I wanna catch it and display an error messsage in my managed bean.

PS: In my managed bean I just call the method :

void addReq(Requirement req){
    try {
        ReqFamily pReqParent = (ReqFamily) selectedNode.getData();
        req.setParent(pReqParent);
        req.addInDB();//here i want to catch it 


        DefaultTreeNode newReqNode = new DefaultTreeNode(req,selectedNode);
        if (pReqParent!=null){
            pReqParent.addRequirement(req);
        }

    } catch (Exception ex){

        ex.printStackTrace();
    }
}
  • 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-14T12:45:42+00:00Added an answer on June 14, 2026 at 12:45 pm

    Its bad practice to catch or throw Exception. If any code you use throws a checked exception then just catch that specific exception, and try to minimize the size of your try-catch blocks.

    class MyException extends Exception {
        ...
    
    public void addInDB() throws MyException {
        if (isInBase()){
            throw new MyException ("[ReqFamily->addInDB] requirment already in base");
        }
        ...
    
    void addReq(Requirement req){
        ReqFamily pReqParent = (ReqFamily) selectedNode.getData();
        req.setParent(pReqParent);
    
        try {
            req.addInDB();
        } catch (MyException ex){
            ex.printStackTrace();
        }
    
        DefaultTreeNode newReqNode = new DefaultTreeNode(req,selectedNode);
        if (pReqParent!=null){
            pReqParent.addRequirement(req);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a simple method that does this: private void searchButton_Click(object sender, EventArgs e)
I've got a GET method that looks like the following: GetMethod method = new
I've got a function that often throws an exception (SSH over 3g). I'd like
I've got a method that does some IO that generally looks like this: public
I want a method that can throw any Throwable including sub classes of Exception.
Say I have a method like this: public void SaveData() { try { foreach
I am trying to test that a particular method throws an expected exception from
I've got a method that gets called on an event, which presents me with
I've got a method that creates a string then appends additional strings onto it:
Let's say I've got a method that takes some arguments and stores them as

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.