Hi everyone, I have a problem relating to how i should handle non fatal errors. I have a static method to which i pass a List. The static method loops through the list, does some processing based on the contents of the list and then returns a new list object as a result. As i am processing an object in the list it is possible that an error may arise that may not allow me to process that object. However i do not wish to terminate the processing of the list (i.e. i want to continue looping through the list). I log the error and continue. However i need someway of indicating that an error has occurred and that when my application has finished executing that the user should check the log file. I cannot throw an exception within the method as this would cause me to exit from the loop of processing all the objects in the list and i dont want this. I cannot return some type of error object as i already return the results of the processing. So how do i indicate that somthing is not right. The only solution i have thought about is to pass some kind of collection object to the method to which i can add error strings when somthing goes wrong. When the method is finished executing the client of the method can check if there are any entries in the error Collection object it passed to the method. If there are then it will warn the application user. Can anyone think of a better way of doing this?? Thanks, John [ August 01, 2002: Message edited by: John Ryan ]
John, I'd say that your solution sounds like the best idea. The reverse might also work. Have the method return the error codes, or perhaps just a boolean, and add the processed objects to a List (passed to it as a parameter). -Stu
Joined: Mar 14, 2001
Originally posted by Cindy Glass: You might want to look into Loggers.
Hi Cindy. I am actually using log4j so its not the logging of the error that it is the problem. My problem revolves around how to indicate to the cleint of my method that an error has occurred without throwing an exception. Logging the error is one step but you need a way to indicate to the user that an error occurred and please check the error log for detaisl...
Well , I believe in " When in doubt, create another class" ;-) I would wrap the results of what you're passing back from the method in a class that contains your original return value , plus suitable error codes/messages
Joined: Sep 29, 2000
So if you logged an error, why don't you just force open the Log file for the user and SHOW it to him? Or just write a message to the GUI or console telling him to go look at it.
Originally posted by Ronald Francis: Well , I believe in " When in doubt, create another class" ;-) I would wrap the results of what you're passing back from the method in a class that contains your original return value , plus suitable error codes/messages
Either that or use an object instead of a static method, so that you could do something like
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Mar 14, 2001
Originally posted by Cindy Glass: So if you logged an error, why don't you just force open the Log file for the user and SHOW it to him? Or just write a message to the GUI or console telling him to go look at it.
Writing a message to the console is exactly what i want to do. I suppose as i am using log4j which can write to many locations i could use it to write the error to the console and not worry about returning the error message from the method..........