From 70fc0505b223f7bf17d3671d0532773359cf7858 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 20 Jun 2025 18:47:45 +0300 Subject: Implement proper exception hierarchy and consistent error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create base exception classes: - VSSimulatorException: Base checked exception for all simulator errors - VSSimulatorRuntimeException: Base unchecked exception for unrecoverable errors - Refactor existing exceptions to extend from base class: - VSEventNotCopyableException: Now includes better error messages - VSParseIntegerVectorException: Added constructors with cause support - VSNegativeNumberException: Added field name and value parameters - Add new specific exception types: - VSConfigurationException: For configuration errors - VSSerializationException: For save/load operations - VSProcessException: For process-related errors - VSProtocolException: For protocol execution errors - Create VSErrorHandler utility class: - Centralized error logging and user notification - Consistent error handling patterns - Helper methods for warning and error dialogs - Update exception handling in code: - VSClassLoader: Better error messages and specific exception handling - Timestamp events: Catch RuntimeException for custom actions - All 132 unit tests pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/main/java/exceptions/VSProcessException.java | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/exceptions/VSProcessException.java (limited to 'src/main/java/exceptions/VSProcessException.java') diff --git a/src/main/java/exceptions/VSProcessException.java b/src/main/java/exceptions/VSProcessException.java new file mode 100644 index 0000000..3c0910b --- /dev/null +++ b/src/main/java/exceptions/VSProcessException.java @@ -0,0 +1,56 @@ +package exceptions; + +/** + * Exception thrown when there is an error related to process operations in the simulator. + * This includes process creation, communication, or state management errors. + * + * @author Paul C. Buetow + */ +public class VSProcessException extends VSSimulatorException { + /** The serial version uid */ + private static final long serialVersionUID = 1L; + + private final int processId; + + /** + * Constructs a new process exception with the specified detail message. + * + * @param message the detail message + */ + public VSProcessException(String message) { + super(message); + this.processId = -1; + } + + /** + * Constructs a new process exception for a specific process. + * + * @param processId the ID of the process that encountered the error + * @param message the detail message + */ + public VSProcessException(int processId, String message) { + super(String.format("Process %d: %s", processId, message)); + this.processId = processId; + } + + /** + * Constructs a new process exception with the specified detail message and cause. + * + * @param processId the ID of the process that encountered the error + * @param message the detail message + * @param cause the cause + */ + public VSProcessException(int processId, String message, Throwable cause) { + super(String.format("Process %d: %s", processId, message), cause); + this.processId = processId; + } + + /** + * Gets the process ID associated with this exception. + * + * @return the process ID, or -1 if not specific to a process + */ + public int getProcessId() { + return processId; + } +} \ No newline at end of file -- cgit v1.2.3