Tagged Questions
2
votes
2answers
95 views
What to do with the Exception when you fail to close() a resource?
I am happy to receive all recommendations for improvement. But below I am mostly interested in a review of my handling of the exception thrown by the close() method of RandomAccessFile.
The ...
1
vote
1answer
36 views
When to catch/wrap an exception vs declaring that method throws exception
In the snippet below the three exceptions I declare in the throws clause are all thrown by BeanUtils.setProperty(), which is a third party library.
Is letting these three exceptions "bubble upwards" ...
5
votes
1answer
132 views
Get rid of pokemon exception handling
I wrote a productivity app for Android. It let's you switch system settings, like bluetooth, wifi, screen brightness, volumes, ringtones, mobile data, airplane mode, etc. Unfortunately I have ...
3
votes
3answers
66 views
Reading image from jar
I am using this static method in my class IconManager to read an image from jar file. imagepath is a relative path to the image.
This code works perfect. But I was told it is error-prone, because ...
4
votes
1answer
93 views
Attempt at an implementation of a TextFile class
How can I improve this class that should represent a text file?
Im trying to write a simple class to represent a text file - which one would think should be quite easy.. I don't intend to add all ...
6
votes
3answers
259 views
Exception handling, et al - How do I make this not “poor”?
I haven't done Java coding in years, but I thought I would give it a shot for a job interview. I have a few questions:
Why is this error handling considered poor? How am I supposed to be doing it?
...
5
votes
2answers
163 views
Return inside try block
Is this return style acceptable? Would the code be more readable if I assigned the MonthDay.parse() return value to a variable and returned that variable on the last line?
Also, is it a bad idea to ...
4
votes
3answers
193 views
Refactor this exception handling code
I am having difficulty deciding how to implement an exception handling strategy.
I am using an observer pattern to allow "plugin" programmers to subscribe to Messages. These subscribers generally log ...
6
votes
4answers
323 views
Does this code follow standard conventions?
I’m trying to learn as much as I can on my own by reading lots of examples, documentations, and asking here. I would like to improve my style to write efficient code and adhere to Java standards.
In ...
1
vote
2answers
147 views
Throwing the Exception But Using the Finally Block
Does this piece of code make sense? The idea is to throw any exceptions that may occur but always run the finally block to close the streams.
private void streamToFile(HttpResponse transferResponse) ...
6
votes
3answers
323 views
When to catch a general exception
I have a class which throws alot of exceptions :
try {
mapper.writeValue(outStream, myVal);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch ...
2
votes
2answers
542 views
HttpClient error handling
I would be happy to hear feedback on my implementation of httpclient. I am not so strong with error handling so I want to improve. My thought process behind this was that IOExceptions can be ...
2
votes
3answers
158 views
Exception handling continuing the excecution
This code is for continuing the execution after an exception, and this is ugly:
int step=0;
do{
try{
switch(step)
{
case 0:
...
6
votes
6answers
673 views
How to reduce the amount of try/catch in my code?
I have the following code that checks for three different properties. Unfortunately each call can throw up to four exceptions that I all have to catch. Can I some how make the code more readable by ...
2
votes
1answer
795 views
Validating files and returning errors messages/boolean values
I am writing simple file validator for my java ee app and I am stack with my class api. I need specific error descriptions, but also I would like to have boolean values indicating whether file is ...