package com.nucleus.opengl;

import java.util.ArrayList;
import java.util.List;

/**
 * An exception for GL / GLES error codes, since GL and GLES are based on C APIs there is no support for Exceptions
 * in the API.
 * Use this exception when there is an error reported from GL / GLES.
 * 
 * @author Richard Sahlin
 *
 */
public class GLException extends Throwable {

    /**
     * One or more error codes from OpenGL/ES
     */
    private List<Integer> errorCodes = new ArrayList<Integer>();

    /**
     * Creates a new GLException with detail message and one error code from OpenGL.
     * 
     * @param detailMessage
     * @param errorCode
     */
    public GLException(String detailMessage, int errorCode) {
        super(detailMessage);
        errorCodes.add(errorCode);
    }

    /**
     * Creates a new GLException with message and list of error codes.
     * 
     * @param detailMessage
     * @param errorCodes One or more GLError codes.
     */
    public GLException(String detailMessage, List<Integer> errorCodes) {
        super(detailMessage);
        this.errorCodes = errorCodes;
    }

    /**
     * Returns the error code(s) that are the reason for this exception, can be 1 or more error codes from OpenGL.
     * 
     * @return One or more OpenGL error code(s)
     */
    public List<Integer> getErrorCodes() {
        return errorCodes;
    }

    /**
     * Checks if the exception contains the specified error code, ie the error code is in the list of error codes for
     * this exception.
     * 
     * @param errorCode
     * @return True if the list of error codes in this exception contains errorCode, false otherwise.
     */
    public boolean isErrorCode(int errorCode) {
        for (int error : errorCodes) {
            if (error == errorCode) {
                return true;
            }
        }
        return false;
    }

    /**
     * Utility method to turn this exception into readable string.
     */
    @Override
    public String toString() {
        StringBuffer message = new StringBuffer(getMessage());
        for (int error : errorCodes) {
            message.append(", " + error);
        }
        return message.toString();
    }

}

@@ -362,16 +362,709 @@
 able %7B%0A%0A
+    public enum Error %7B%0A        INVALID_ENUM(0x0500),%0A        INVALID_VALUE(0x0501),%0A        INVALID_OPERATION(0x0502),%0A        OUT_OF_MEMORY(0x0505);%0A%0A        public final int value;%0A%0A        private Error(int value) %7B%0A            this.value = value;%0A        %7D%0A%0A        /**%0A         * Finds the Error enum for the error value%0A         * %0A         * @param value The error value to look up%0A         * @return The error, or null if not found%0A         */%0A        public static Error getError(int value) %7B%0A            for (Error e : Error.values()) %7B%0A                if (e.value == value) %7B%0A                    return e;%0A                %7D%0A            %7D%0A            return null;%0A        %7D%0A%0A    %7D%0A%0A
     /**%0A
@@ -2785,32 +2785,193 @@
 : errorCodes) %7B%0A
+            Error e = Error.getError(error);%0A            if (e != null) %7B%0A                message.append(%22, %22 + e + %22(%22 + error + %22)%22);%0A            %7D else %7B%0A    
             mess
@@ -2988,32 +2988,46 @@
 (%22, %22 + error);%0A
+            %7D%0A
         %7D%0A      

Add some GL error values as enum in GLException