Tuesday, September 24, 2013

How do I stop the error log view popping up in eclipse

In general will log lot of information and errors into the error during the job execution, if that is a long running job it will keep on posting current execution messages to the error log. While posting the message to the error log view, if the view is not focused job will bring the focus to the view.
Sometimes this would be disgusting, if you are working with other view just next to it, beacause focus will always goes back to the error log view, if any message is posted into it by currently running job. To avoid this kind of issue follow the below approach.

In error log view, you can find the drop down menu (small triangle on the top - right of the view), deselect "Activate on new events".

This will avoid the view popping issue when any error or messages are pushed into error log.



Saturday, September 7, 2013

Three rules for effective exception handling in java

If we are dealing with exceptions basically it has to tell you the following things.

1. What went wrong ?
2. Where did it go wrong ?
3. Why did it go wrong ?

so, to address above points we need follow 3 golden rules of exception handling.

1.  Be specific on exception type  -> It should tell what went wrong, ex: file not found, connection not found

2. Throw early - > ex: if you are passing null file name to FileInputStream it throws null pointer exception, but this is not sufficient to the user, instead check whether it is null or not ,then throw an exception that "File name can't be empty".

3. Catch late- > Catch where you want to show it the user immediately. Don't log and catch at the API level or lower level, instead throw from api or lower level and catch at the UI layer or at the top layer.


https://today.java.net/pub/a/today/2003/12/04/exceptions.html




Friday, September 6, 2013

NLS bind with single quote messages

Ex:
NLS.bind("Deleting projects from Account '{0}'",  dataProvider.getCurrentAccount().getName())

This will not give you the desired output.

Output: Deleting projects from Account '{0}'

As per API, Text appearing within single quotes is treated as a literal. A single quote is escaped by a preceeding single quote.

Modify as below:
NLS.bind("Deleting projects from Account ' '{0}' ' ",  dataProvider.getCurrentAccount().getName())

output: Deleting projects from Account KondalKolipaka