Find a throwable message starting with the last element. Returns the first throwable message where throwable.getMessage() != null - Java java.lang

Java examples for java.lang:Throwable

Description

Find a throwable message starting with the last element. Returns the first throwable message where throwable.getMessage() != null

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    /**//from   ww w  .  j a va2s .c o m
     * Find a throwable message starting with the last element.<br />
     * Returns the first throwable message where
     * <code>throwable.getMessage() != null</code>
     */
    public static String getExceptionMessage(List<Throwable> throwables) {
        if (throwables == null) {
            return null;
        }

        for (int i = throwables.size() - 1; i > 0; i--) {
            Throwable t = (Throwable) throwables.get(i);
            if (t.getMessage() != null) {
                return t.getMessage();
            }
        }

        return null;
    }
}

Related Tutorials