
com.vladium.util.exception.AbstractRuntimeException Maven / Gradle / Ivy
/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
*
* This program and the accompanying materials are made available under
* the terms of the Common Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/cpl-v10.html
*
* $Id: AbstractRuntimeException.java,v 1.1.1.1 2004/05/09 16:57:57 vlad_r Exp $
*/
package com.vladium.util.exception;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
// ----------------------------------------------------------------------------
/**
* Based on code published by me in JavaPro, 2002.
*
* This unchecked exception class is designed as a base/expansion point for the
* entire hierarchy of unchecked exceptions in a project.
*
* It provides the following features:
*
* - ability to take in compact error codes that map to full text messages
* in a resource bundle loaded at this class' instantiation time. This avoids
* hardcoding the error messages in product code and allows for easy
* localization of such text if required. Additionally, these messages
* can be parametrized in the java.text.MessageFormat style;
*
- exception chaining in J2SE versions prior to 1.4
*
*
* See {@link AbstractException} for a checked version of the same class.
*
* TODO: javadoc
*
* Each constructor that accepts a String 'message' parameter accepts an error
* code as well. You are then responsible for ensuring that either the root
* com.vladium.exception.exceptions
resource bundle
* or your project/exception class-specific resource bundle [see
* below for details] contains a mapping for this error
* code. When this lookup fails the passed String value itself will be used as
* the error message.
*
* All constructors taking an 'arguments' parameter supply parameters to the error
* message used as a java.text.MessageFormat pattern.
*
* Example:
*
* File file = ...
* try
* ...
* catch (Exception e)
* {
* throw new AbstractRuntimeException ("FILE_NOT_FOUND", new Object[] {file, e}, e);
* }
*
* where com.vladium.util.exception.exceptions
contains:
*
* FILE_NOT_FOUND: file {0} could not be opened: {1}
*
*
* To log exception data use {@link #getMessage} or printStackTrace
* family of methods. You should never have to use toString().