Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions chess/3-web-api/web-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ 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]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be helpful to give an example of why you might want to add other classes and possibly point to the exception instruction rather than the note.

We might want to enhance the exception instruction to actually give an example in the custom exception section that shows how to extend the exception class and why you would do it.

>
> 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

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.
Expand Down
9 changes: 9 additions & 0 deletions instruction/exceptions/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down