diff --git a/base/src/org/adempiere/exceptions/AdempiereException.java b/base/src/org/adempiere/exceptions/AdempiereException.java new file mode 100644 index 0000000000..c8daf96fad --- /dev/null +++ b/base/src/org/adempiere/exceptions/AdempiereException.java @@ -0,0 +1,84 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package org.adempiere.exceptions; + +import java.util.Properties; + +import org.compiere.util.CLogger; +import org.compiere.util.Env; +import org.compiere.util.Msg; + +/** + * Any exception that occurs inside the Adempiere core + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + */ +public class AdempiereException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * Default Constructor (saved logger error will be used as message) + */ + public AdempiereException() { + this(getMessageFromLogger()); + } + + + /** + * @param message + */ + public AdempiereException(String message) { + super(message); + } + + /** + * @param cause + */ + public AdempiereException(Throwable cause) { + super(cause); + } + + /** + * @param message + * @param cause + */ + public AdempiereException(String message, Throwable cause) { + super(message, cause); + } + + @Override + public String getLocalizedMessage() { + String msg = super.getLocalizedMessage(); + msg = Msg.parseTranslation(getCtx(), msg); + return msg; + } + + protected Properties getCtx() { + return Env.getCtx(); + } + + + /** + * @return error message from logger + * @see org.compiere.util.CLogger#retrieveError() + */ + private static String getMessageFromLogger() { + org.compiere.util.ValueNamePair err = CLogger.retrieveError(); + String msg = null; + if (err != null) + msg = err.getName(); + if (msg == null) + msg = "UnknownError"; + return msg; + } +} diff --git a/base/src/org/compiere/model/PO.java b/base/src/org/compiere/model/PO.java index 9ecd41e832..76eb7a8275 100644 --- a/base/src/org/compiere/model/PO.java +++ b/base/src/org/compiere/model/PO.java @@ -39,6 +39,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.adempiere.exceptions.AdempiereException; import org.compiere.Adempiere; import org.compiere.acct.Doc; import org.compiere.util.CLogMgt; @@ -53,6 +54,7 @@ import org.compiere.util.Msg; import org.compiere.util.SecureEngine; import org.compiere.util.Trace; import org.compiere.util.Trx; +import org.compiere.util.ValueNamePair; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -63,7 +65,10 @@ import org.w3c.dom.Element; * @author Jorg Janke * @version $Id: PO.java,v 1.12 2006/08/09 16:38:47 jjanke Exp $ * - * @author Teo Sarca - FR [ 1675490 ], BF [ 1704828 ] + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + *