/**
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
 * If a copy of the MPL was not distributed with this file, You can obtain one at
 * http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is also subject to the terms of the Health-Related Additional
 * Disclaimer of Warranty and Limitation of Liability available at
 * http://www.carewebframework.org/licensing/disclaimer.
 */
package org.carewebframework.vista.mbroker;

import org.apache.commons.lang.StringUtils;

/**
 * Wraps exceptions returned by an RPC.
 */
public class RPCException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    private int code = 0;

    /**
     * Exception information parsed from the RPC return value.
     */
    private static class ExceptionInfo {

        private int code;

        private String text;

        private ExceptionInfo(String text) {
            int i = text.indexOf(Constants.LINE_SEPARATOR);
            String first = i < 1 ? "" : text.substring(0, i);

            if (StringUtils.isNumeric(first)) {
                code = Integer.parseInt(first);
                this.text = text.substring(++i);
            } else {
                this.text = text;
            }
        }
    }

    /**
     * Creates an exception based on the error text.
     *
     * @param text Error text returned by RPC.
     */
    public RPCException(String text) {
        this(new ExceptionInfo(text));
    }

    /**
     * Creates an exception from the parsed text.
     *
     * @param value Exception information.
     */
    private RPCException(ExceptionInfo value) {
        super(value.text);
        this.code = value.code;
    }

    /**
     * Returns the error code.
     *
     * @return The error code.
     */
    public int getCode() {
        return code;
    }

    @Override
    public String toString() {
        return code + ": " + super.toString();
    }
}

@@ -608,17 +608,21 @@
 ption %7B%0A
+    
 %0A
-
     priv
@@ -666,17 +666,21 @@
 D = 1L;%0A
+    
 %0A
-
     priv
@@ -697,17 +697,21 @@
 de = 0;%0A
+    
 %0A
-
     /**%0A
@@ -822,17 +822,25 @@
 nInfo %7B%0A
+        
 %0A
-
         
@@ -857,17 +857,25 @@
 t code;%0A
+        
 %0A
-
         
@@ -895,17 +895,25 @@
 g text;%0A
+        
 %0A
-
         
@@ -1071,17 +1071,29 @@
 (0, i);%0A
+            
 %0A
-
         
@@ -1310,25 +1310,29 @@
     %7D%0A    %7D%0A
+    
 %0A
-
     /**%0A    
@@ -1518,33 +1518,299 @@
 o(text));%0A    %7D%0A
+    %0A    /**%0A     * Creates an RPC exception from an error code and text.%0A     * %0A     * @param code The error code.%0A     * @param text The error text.%0A     */%0A    public RPCException(int code, String text) %7B%0A        super(text);%0A        this.code = code;%0A    %7D%0A    
 %0A
-
     /**%0A     * C
@@ -1969,65 +1969,44 @@
     
-super
+this
 (value.
-text);%0A        this.
 code
- =
+,
  value.
-code
+text)
 ;%0A    %7D%0A
 %0A   
@@ -1997,25 +1997,29 @@
 ext);%0A    %7D%0A
+    
 %0A
-
     /**%0A    
@@ -2145,16 +2145,20 @@
 ;%0A    %7D%0A
+    
 %0A    @Ov

Add an additional constructor to RPCException.