Guide to Object-oriented Programming With Java (Buffalo State University Version)
Chapter 11: Java Exceptions and Error Logging
Java provides a number of utilities that allow you to handle exceptions (errors) gracefully. You can even throw your own custom exceptions or the Apache Log4j 2 utilities to write errors to a file.
Handling Exceptions Using
For example, you may want to make sure the user enters a Double and not a letter or other non-number:
If the user enters a non-number:
Java Error Logging
As mentioned above, you can use the Apache Log4j 2 utilities to write execptions and errors to a log file.
Now create a new ApacheLogging class using the
ApacheLogging.java which should produce this output in your
log -> test.log file:
Let's get started with a TryCatch program!