0

Following the example (based on a similar question):

/**
 * 
 */
package za.co.sindi.jsf.functions;

import java.io.IOException;

import org.markdown4j.Markdown4jProcessor;

/**
 * 
 * @author Buhake Sindi
 * @since 22 January 2013
 *
 */
public final class SomeFunctions {

    /**
     * Private constructor
     */
    private SomeFunctions() {
        //TODO: Nothing...
    }

    public static String process(String input) {
        SomeProcessor processor = new SomeProcessor();
        try {
            return processor.process(input);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();  //I don't believe this is correct.
        }
    }
}

What do I do inside the catch block? Do I just log it on a java Logger or is there a preferred JSF way on encapsulating an Exception?

Community
  • 1
  • 1
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228

1 Answers1

1

Depends on the concrete functional requirements.

If an empty output is acceptable, log it and return null.

public static String process(String input) {
    SomeProcessor processor = new SomeProcessor();
    try {
        return processor.process(input);
    } catch (IOException e) {
        someLogger.warn("Processing markdown failed", e);
        return null;
    }
}

If it's not acceptable, throw it.

public static String process(String input) throws IOException {
    SomeProcessor processor = new SomeProcessor();
    return processor.process(input);
}

Unrelated to the concrete problem, you'd better process markdown and store as property (and ultimately also in DB) only once during create/update instead of processing the very same output again and again. So, effectively you end up with 2 properties / DB columns, one with raw markdown and another with parsed/processed markdown.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks @BalusC! By the way, thanks for identifying my **unrelated** problem. I have 2 columns, one that stores raw markdown and one that stores as plaintext. I see your approach now. Thanks! :-) – Buhake Sindi Jan 22 '14 at 21:18