From ef67bcb9209b44fd5740d1181b4149eae731e7ff Mon Sep 17 00:00:00 2001 From: Jacob <40241584+bsharplydian@users.noreply.github.com> Date: Fri, 3 Apr 2026 12:43:42 -0600 Subject: [PATCH 1/3] add: note to DataAccessException introduction. Indicates that adding more Exception classes could be helpful. --- chess/3-web-api/web-api.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chess/3-web-api/web-api.md b/chess/3-web-api/web-api.md index 31c2464e..77145697 100644 --- a/chess/3-web-api/web-api.md +++ b/chess/3-web-api/web-api.md @@ -190,6 +190,9 @@ void insertUser(UserData u) throws DataAccessException The starter code includes a `dataAccess.DataAccessException`. This exception should be thrown by data access methods that could fail. If a method call fails, it should throw a `DataAccessException`. For example, the `DataAccessException` is thrown if a user attempts to update a non-existent game. If you like, feel free to create subclasses of DataAccessException that represent more specific errors relating to data access. +> [!NOTE] +> In Phases 3-6, you may find it helpful to create more exception classes besides DataAccessException. + ### Example Data Access Methods Here are some examples of the kinds of methods your DAOs will need to support. This list is not exhaustive. You should consult your server design in order to determine all of the methods you need to provide. From bfa22c248a297bc84c3f3e92b858c96df269e2ae Mon Sep 17 00:00:00 2001 From: Jacob <40241584+bsharplydian@users.noreply.github.com> Date: Tue, 28 Apr 2026 10:30:58 -0600 Subject: [PATCH 2/3] add: clarification to DataAccessException note, linking to exception instruction --- chess/3-web-api/web-api.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chess/3-web-api/web-api.md b/chess/3-web-api/web-api.md index 77145697..da77594f 100644 --- a/chess/3-web-api/web-api.md +++ b/chess/3-web-api/web-api.md @@ -191,7 +191,12 @@ void insertUser(UserData u) throws DataAccessException The starter code includes a `dataAccess.DataAccessException`. This exception should be thrown by data access methods that could fail. If a method call fails, it should throw a `DataAccessException`. For example, the `DataAccessException` is thrown if a user attempts to update a non-existent game. If you like, feel free to create subclasses of DataAccessException that represent more specific errors relating to data access. > [!NOTE] -> In Phases 3-6, you may find it helpful to create more exception classes besides DataAccessException. +> +> In Phases 3-6, you may find it helpful to create more exception classes besides `DataAccessException`. This will help you stay organized and write cleaner code. +> +> For example, you might add an `AlreadyTakenException` to throw when the user tries to register an existing username. +> +> See [this page](../../instruction/exceptions/exceptions.md) for examples of creating your own exceptions. ### Example Data Access Methods From 9aa1bd23452bcc798d507b84193a7c5f7c187572 Mon Sep 17 00:00:00 2001 From: Jacob <40241584+bsharplydian@users.noreply.github.com> Date: Tue, 28 Apr 2026 10:31:21 -0600 Subject: [PATCH 3/3] add: custom exception example --- instruction/exceptions/exceptions.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/instruction/exceptions/exceptions.md b/instruction/exceptions/exceptions.md index f992aa3e..0c7b1674 100644 --- a/instruction/exceptions/exceptions.md +++ b/instruction/exceptions/exceptions.md @@ -127,6 +127,15 @@ public class ExceptionExample { Java has many useful Exception types you can `throw`, but often you won't find one that matches what you need. You can create your own exception types by creating subclasses of the `Exception` class (or of any other exception type). Feel free to add fields to your exception classes to contain any information that might be useful about what went wrong. If you find yourself catching an exception and then checking the message string to see what kind of error it is, you may want to replace it with a custom exception type instead. +Here is an example of a custom exception type: +```java +public class AlreadyTakenException extends Exception { + public AlreadyTakenException(String message) { + super(message) + } +} +``` + ## Try-With-Resources Not closing resources, such as file handles or database connections, can lead to leaks that will cause your application to fail. The following example shows the allocation of an input stream that closes the stream after it is used. However, if an exception is thrown during the read operation the stream is not closed and the file handle is leaked. That means the resources associated with the file are never released and eventually that application will not be able to open files.