aspose file tools*
The moose likes Java in General and the fly likes Indicate non-fatal error without Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Indicate non-fatal error without Exception" Watch "Indicate non-fatal error without Exception" New topic
Author

Indicate non-fatal error without Exception

John Ryan
Ranch Hand

Joined: Mar 14, 2001
Posts: 124
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 ]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You might want to look into Loggers.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Stu Glassman
Ranch Hand

Joined: Jul 01, 2002
Posts: 91
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
John Ryan
Ranch Hand

Joined: Mar 14, 2001
Posts: 124
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...
Ronald Francis
Ranch Hand

Joined: Aug 02, 2001
Posts: 30
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
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
If I understand the question - you can throw an exception from deep within whatever processing you're doing, and then catch it just inside the iterator loop:

[ August 01, 2002: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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
John Ryan
Ranch Hand

Joined: Mar 14, 2001
Posts: 124
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..........
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Yeah . . .
 
jQuery in Action, 2nd edition
 
subject: Indicate non-fatal error without Exception