Current Status (11/19/07) - following issues resolved
- search for all e.printStackTrace() and remove and handle appropriately
- matching to issue 1~3, 10
- search for all swallowed exceptions and emit appropriately
- matching to issue 1~3, 8
- org.knownspace.fluency.engine.core.exceptions* to be subclasses of FluencyException and move to org.knownspace.fluency.shared.exceptions
- matching to issue 9
Current Status (11/11/07)
- Abstract class FluencyException extends RuntimeException and is intended to be the base exception for all Exceptions generated by Fluency.
- Two exceptions have been created which extend this base Exception:
- FatalFluencyException
- NonFatalFluencyExeption
The expectation is that all application exceptions will be subclasses of one of these two types.
- FatalFluencyException
- FluencyException is abstract because it is cleaner to force instantiation of one of the above subtypes.
- main methods in Fluency.java and FluencyEngine.java are catching exceptions like this:
sample main method
public static void main(String[] args) { FluencyExceptionUtil.init(); try { FluencyEditorFrame.FLUENCY_WINDOW.start(); } catch (FatalFluencyException ffe) { FluencyExceptionUtil.handleException(ffe); } catch (NonFatalFluencyException nffe) { FluencyExceptionUtil.handleException(nffe); } catch (RuntimeException re) { FluencyExceptionUtil.handleException(new FatalFluencyException(re)); } catch (Exception e) { FluencyExceptionUtil.handleException(new NonFatalFluencyException(e)); } }
The order of the catch blocks is significant (particularly, RuntimeException and Exception) because it allows for cleaner chaining and does not clutter the code in the handler with lots of instanceof if blocks.
- If you want to temporarily turn off exception handling when you are debugging a problem (and you do not want Fluency to terminate on Fatal exceptions) you can turn off exception handling by setting handle_exceptions=false as an environment variable. The default is always on.
You can do this easily in Eclipse (open run dialog --> environment tab for your executable class). - If you are throwing an exception in a catch block that is a subclass of FluencyException then it is not necessary to log the exception. Logging is handled implicitly by FluencyException.
Outstanding Issues (updated 11/11/07 – includes New items)
1. Much of the current code base does not throw Exceptions in a typical Java fashion.
exceptions are swallowed throughout the codebasemajority of methods do not use throws clausetype Exception is caught rather than the most specific exception that applies
2. In many places we do not need to catch exceptions but should just throw them to be handled further up the call stack
3. We cannot use "brute force" approach to change all methods which now swallow exceptions to instead throw all exceptions because sometimes we actually want to ignore the problem and do something else
- see TagXMLHandler.getTags() where we return an Empty Tag object if we could not the load one from file
| Update for Items 1 - 3 I have fixed exception swallowing in a few places. Here is what I think we should all be aware of as we are working in the codebase:
|
4. We need to integrate the Log4J logging framework into the handling of exceptions
| Update for Item 4 Resolved. Handled implictly when exceptions are created which are subclasses of FluencyException. This also applies to chaining exceptions inside a FluencyException. |
5. A number of constructors have A LOT of logic in them and many are calling methods which presently swallow exceptions. It is generally discouraged to throw exceptions from a constructor.
One solution is to refactor to use factory patternIn at least a few cases this is true of a singleton class (see FluencyEditorFrame) so need an approach for this case
6. A number of overridden swing interface methods do not allow for a throws clause. For example:
interface ActionListener { public void actionPerformed(ActionEvent actionEvent); }
7. We need to consider how we will report errors vs exception. For example:
class MyActionListener {
public void actionPerformed(ActionEvent actionEvent) {
// do something which may cause an exception like IOException
// but cannot throw an exception from this method.
// Should we create a light Error Message reporting framework for this?
}
}
| Update for Items 5 - 7 Since our base exception subclasses RuntimeException, these are no longer concerns. |
8. Right now, generally only Unchecked (i.e. traditional Java Runtime exceptions) will trigger the dialog to display a message to the user because most Checked exceptions are swallowed.
| Update for Item 8 This is the case because we swallow (obviously!) so many exceptions. See the guidelines in the update for Items 1 - 3 to resolve this. |
9. New! Need to change "legacy" exceptions in org.knownspace.fluency.engine.core.exceptions* to be subclasses of FluencyException and move to org.knownspace.fluency.shared.exceptions
10. New! Need to search for all e.printStackTrace() and remove and handle appropriately per the steps listed in update to item 1 - 3.
Comments (8)
Nov 05, 2007
whoknows says:
excellent. this is going to take some time. sigh. gjer. ps. from your (6) above ...excellent. this is going to take some time. sigh.
gjer.
ps. from your (6) above i now understand that problem a bit better. (7) seems very similar. will mull it over.
Nov 07, 2007
yonghyun says:
In respect to issue 6, and 7, I posted my idea and experiment on that. Using thr...In respect to issue 6, and 7,
I posted my idea and experiment on that.
Using throwable logging
Nov 11, 2007
whoknows says:
excellent. gjer.excellent.
gjer.
Nov 11, 2007
whoknows says:
great work, michelle. i now think that with what you've done it shouldn't be an ...great work, michelle. i now think that with what you've done it shouldn't be an impossibly hard task to convert everything this coming week, rather than do it piecemeal as people refactor. i especially think so as no one has yet made use of any of your great work.
gjer.
Nov 11, 2007
Michelle Wynn says:
Yes I agree...I think most could be done as one big effort rather than piecemeal...Yes I agree...I think most could be done as one big effort rather than piecemeal.
There are a few places I've come across where it may be tricky but I think most places will be fairly straightforward to change. In such places, we can, at a minimum, chain the most specific checked exception possible in a new FluencyException.
Nov 11, 2007
whoknows says:
i fully agree. i'm very very happy with your work. gjer.i fully agree.
i'm very very happy with your work.
gjer.
Nov 13, 2007
yonghyun says:
my email setting has some problem, even though I replied to fluency team, I'm af...– my email setting has some problem, even though I replied to fluency team, I'm afraid it's not working properly.
Thus I also left the issue related to my previous commit.
I understand the problem both of you pointed out.
And also Michelle, your report was clear, that was my fault.
I was confused with some points.
It's not an adequate excuse, but before I started this task, I made some test case for chained exception flows.
e.g.
try
System.out.println("Can reach to this line?");
the result is ...
------------------------------
-----------------------------------------------------------------------------------
[ERROR | 2007-11-13 12:58:29,203] org.knownspace.fluency.shared.exceptions.FluencyException.main (39 line) ::
Handled Exception: io error
java.io.IOException
at sandbox.exceptions.Test.main(Test.java:11)
Can reach to this line?
------------------------------------------------------------------------------------------------------------------
However, I thought the above code 'System.out.println("Can reach to this line?");'
was not reached at that time. (I don't know what was the runtime problem and why I misjudged at that time.)
From this reason, I intended to guarantee the flowing code lines (after try-catch block),
even though I inserted inadequate invocation like following.
– FluencyExceptionUtil.handleException(new NonFatalFluencyException(message, ex));
I'm sorry for bothering you. And thank you for letting me know correctly.
Yonghyun.
Nov 13, 2007
whoknows says:
re: " my email setting has some problem, even though I replied to fluency team, ...re: "- my email setting has some problem, even though I replied to fluency team, I'm afraid it's not working properly."
it's because you emailed the list from the wrong address. one other person made the same mistake today to. i deleted them all. you can add new addresses as you please to the mailing list handler. this was covered in class ad nauseum weeks ago.
gjer.