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 --- .../java/exceptions/VSNegativeNumberException.java | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/main/java/exceptions/VSNegativeNumberException.java') diff --git a/src/main/java/exceptions/VSNegativeNumberException.java b/src/main/java/exceptions/VSNegativeNumberException.java index edf2049..a2f5bf6 100644 --- a/src/main/java/exceptions/VSNegativeNumberException.java +++ b/src/main/java/exceptions/VSNegativeNumberException.java @@ -1,12 +1,38 @@ package exceptions; /** - * The Interface VSNegativeNumberException, this exception is thrown if - * a negative number has returned if a positive number has been expected. + * Exception thrown when a negative number is encountered where a positive number is expected. + * This is typically used for validation of numeric inputs that must be non-negative. * * @author Paul C. Buetow */ -public class VSNegativeNumberException extends Exception { +public class VSNegativeNumberException extends VSSimulatorException { /** The serial version uid */ private static final long serialVersionUID = 1L; + + /** + * Constructs a new negative number exception. + */ + public VSNegativeNumberException() { + super("Negative number not allowed"); + } + + /** + * Constructs a new negative number exception with the specified field name. + * + * @param fieldName the name of the field that contained the negative number + */ + public VSNegativeNumberException(String fieldName) { + super("Negative number not allowed for field: " + fieldName); + } + + /** + * Constructs a new negative number exception with the specified field name and value. + * + * @param fieldName the name of the field that contained the negative number + * @param value the negative value that was encountered + */ + public VSNegativeNumberException(String fieldName, long value) { + super(String.format("Negative number not allowed for field '%s': %d", fieldName, value)); + } } -- cgit v1.2.3