How can i process A Multi exception Exception on a file with multiple issues to be reported.
I have a case of multi processing step where different exceptions can occur (e.g they will be made asynchronous later). I am using (might be anti-pattern for fail fast) list of exceptions then once they are completed and check for exceptions
I have my own customized exceptions category (For each asynch tasks) (extends Exception
class) but implements an interface to have additional information like a key value pair specific to the message
Sample Implementation
List<Files> Folder;
//Now processed into below folders
List<Files> EnglishFolder;
List<Files> KoreanFolder;
List<Files> SpanishFolder;
//Now each task accumulates own exceptions.
EnglishException extends Exception implements InfoMapping
{
private EnumMap<CUSTOMENUM,STRING> info;
EnglishException(String message){super(message);}
EnglishException(String message, Exception why){super(message);}
public void addInfo(CUSTOMENUM key,String value){info.add(key,value}
}
My problem is if I know what issues i create these exception objects in each tasks but i don't throw them. But if there are general exceptions i just catch them and add it as
List<EnglishException> englishErrors;
//blah blah
englishErrors.add(new EnglishException("I found this error"));
//if generic exception in catch
englishErrors.add(new EnglishException("Unknown English error",e));
//returns without throwing exception
Now i need to synch up all tasks
neatly package all exceptions into an XML file
so i need to support 1 exception class that supports a list of Exceptions class
has only this Exception(String message, Throwable cause)
only supports single inner exception.
2 questions:
- Should I implement another interface and have a special exception class implementing that and override innerException to be list? or am i missing something in java that supports multi inner exceptions? or any other sound practice for doing this?
Being new to streams, can i make the above logic more readable/simple like (am very naive to java 8, just reading so forgive me if it doesnt make any sense). Not looking to get answers, may be just pointers to what in streams to look for to achieve this.
Streams.Of(englishExceptionList,spanishExceptionList)
.reduce(parentException)
.ifAny(throw parentException)