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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:16:12+00:00 2026-05-31T16:16:12+00:00

I have to refactor a Java program created with Eclipse RCP. My predecessor handed

  • 0

I have to refactor a Java program created with Eclipse RCP. My predecessor handed over a ViewPart Implementation through several calls down to the class I want to write Unit Tests for. The ViewPart is handed over for exception handling purposes. Every time an error occurs the error message will be written onto the ViewPart’s StatusLineManager.

What I want to do now is to change this exception handling process, because it causes me a lot of problems when I want to make my Unit Tests.

Is there a way to pass these Exceptions to the ViewPart without handing it down over several method calls?

My initial ideas to create some kind of ExceptionMessenger class that will be initialized every time an exception occurs. But I didn’t find a way to access the ViewPart then.

edit
code example:

class A {
    void func() {
         B.funcB(arg, arg1, arg2, ViewPart view):
    }
}

class B {
      void funcB(arg, arg1, arg2, ViewPart view) {
           C.funcC(arg, arg1, ViewPart view);
      }
}

class C {
    void funcC(arg, arg1, ViewPart view) {
        try{
             doSomeThing():
        catch(Exception e) {
            doSomeErrorMessages(e, view);
        }
     }

    void doSomeErrorMessages(e, ViewPart view) {
        SomeOtherClass.writeToStatusLine( StatusCategory.Processing, e.getMessage(), view); 
    }
 }

class SomeOtherClass {
    void writeToStatusLine(final StatusCategory category, final String message, final ViewPart view) {
    IActionBars bars = view.getViewSite().getActionBars();
        IStatusLineManager statusLineManagerRef = bars.getStatusLineManager();
        statusLineManagerRef.setErrorMessage(null); // clear any error msg

        doWhatEver();
    }
 }
  • 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-31T16:16:14+00:00Added an answer on May 31, 2026 at 4:16 pm

    If I understood your task correctly, there are two parts where you are dealing with exceptions:

    • Java’s exception handling when some exceptional behaviour occurs. For this, you should stick to what Java offers you, as described, e.g., in Josh Bloch’s Effective Java, Item 57 ( Use exceptions only for exceptional conditions).
    • Visualisation of exceptions in your tool (by ViewPart). Since this is not part of exception handling to recover or otherwise cope with exceptional conditions, I would deliberately not use Java’s exception handling for that, i.e. avoid misusing exception handling for control flow. Hence I think your predecessor’s design to pass down the ViewPart to then pass the Exceptions as parameters to your ViewPart is good.

    An alternative would be to let the exceptions get thrown upward and then at some sensible border of layer/framework do the visualisation. But

    • be careful not to mix the two parts of dealing with exceptions listed above
    • if you are dealing with checked exceptions and can handle them far down in your call hierarchy, this will make your code much uglier than passing down ViewPart (and definitely mix the two parts listed above).

    What are your problems when unit testing?

    • If the ViewPart is making trouble: mock it.
    • If passing the ViewPart as parameter is annoying you: use some framework for your dependency injection, e.g. Spring or Guice.
    • If an alternative visualisation/handling of the Exceptions is making trouble: might a (junit-)rule solve the problem?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I refactor(move) a Java method in classA into classB and have all
I'm using RabbitMQ and trying to refactor my current native java implementation to using
I am doing project euler question 33 and have divised a refactor to solve
I have trouble finding way to correctly refactor this code so that there would
I have got a very nasty piece of code i would like to refactor
I have inherited an old crusty PHP application , and I'd like to refactor
I have a large codebase, and I'd like to refactor the package structure so
I have the following code for adding to/extracting from Zip. I'm trying to refactor
It's Friday refactor time!!! I have an object that I use to generate SQL
How would you refactor this, keeping in mind that you have dozens more of

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.