| 1 | package desmoj.core.exception; |
| 2 | |
| 3 | import desmoj.core.report.ErrorMessage; |
| 4 | |
| 5 | /** |
| 6 | * General exception for the desmoj simulation framework. All specific |
| 7 | * exceptions extend this class, thus building a hierarchic tree of possible |
| 8 | * exceptions being thrown by the framework and keeping all simulation related |
| 9 | * exceptions close together. Most exceptions are thrown when the continuation |
| 10 | * of the simulation can not be determined. This is especially the case with |
| 11 | * <code>null</code> references passed to a method expecting valid parameters. |
| 12 | * Note that these exceptions must not be caught by the user and that the user |
| 13 | * does not need to re-throw these exceptions, since they all inherit from class |
| 14 | * <code>java.exception.RuntimeException</code> which has the special feature |
| 15 | * to be re-thrown automatically by any method. |
| 16 | * |
| 17 | * @see java.lang.RuntimeException |
| 18 | * |
| 19 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
| 20 | * @author Tim lechler |
| 21 | * |
| 22 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 23 | * you may not use this file except in compliance with the License. You |
| 24 | * may obtain a copy of the License at |
| 25 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 26 | * |
| 27 | * Unless required by applicable law or agreed to in writing, software |
| 28 | * distributed under the License is distributed on an "AS IS" |
| 29 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 30 | * or implied. See the License for the specific language governing |
| 31 | * permissions and limitations under the License. |
| 32 | * |
| 33 | */ |
| 34 | public class DESMOJException extends RuntimeException { |
| 35 | |
| 36 | /** |
| 37 | * Contains the error message containing a description of the circumstances |
| 38 | * leading to this exception being thrown. |
| 39 | */ |
| 40 | private ErrorMessage _errMsg; |
| 41 | |
| 42 | /** |
| 43 | * Constructs a standard DESMO-J exception with an error message needed to |
| 44 | * properly describe what error occured, where it occured, what reasons |
| 45 | * could be responsible for it and what could be done to prevent this error |
| 46 | * from occuring. |
| 47 | * |
| 48 | * @param message |
| 49 | * desmoj.report.ErrorMessage : Describes the error leading to |
| 50 | * this exception |
| 51 | */ |
| 52 | public DESMOJException(ErrorMessage message) { |
| 53 | |
| 54 | // construct a simple RuntimeException with the description and probable |
| 55 | // error reason as text. |
| 56 | super("DESMOJException\n" |
| 57 | + "Description: " + message.getDescription() + "\n" |
| 58 | + "Location: " + message.getLocation() + "\n" |
| 59 | + "Reason: " + message.getReason() + "\n" |
| 60 | + "Prevention: " + message.getPrevention()); |
| 61 | _errMsg = message; |
| 62 | |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the error message describing the circumstances leading to this |
| 67 | * exception being thrown. Use this method to extract the message and pass |
| 68 | * it to the Experiment's MessageDistributor to write it to the ErrorFile. |
| 69 | * |
| 70 | * @return desmoj.report.ErrorMessage : The errormessage describing the |
| 71 | * reasons for this Exception |
| 72 | */ |
| 73 | public ErrorMessage getErrorMessage() { |
| 74 | |
| 75 | return _errMsg; |
| 76 | |
| 77 | } |
| 78 | } |