In Java there are 2 types of exceptions, checked and unchecked and your code must deal with all the checked exceptions otherwise it won’t compile. Checked exceptions occur when you should expect an exception at least some of the time, so for example opening a file, the file may not exist or you may not have rights to access it, and some exceptions should happen every time (when reading a file, you will reach the end of the file). In contrast an unchecked exception may never happen (a divide by zero, or array out of bounds) or could happen at any time (out of memory, or an array out of bounds). You’ll notice I had an array out of bounds in both cases, this is because depending on how you access the array, so for (String name : names) would never go out of bounds, but name[index] might do depending on how index is calculated.
There are many built in exceptions, but sometimes you may need to provide your own, which you should do by extending one of the base exception classes. If you use an exception that does not need to specified, you can use one that derives from Runtime Exception and if you want an exception that must always be handled use Exception. You can catch exceptions either by the generic form or the more specific form, and you need to catch the most specific versions first. You should not try and catch exceptions if you are not prepared to handle them, it is better to declare in the function header as a throws, do not use an empty catch block as this loses the information that may be helpful in tracking down the problem. A function to read a string from a file, could be defined to return a null in the case of the end of file for example, but it should not catch the FileNotFound exception and return a null in that case as you are losing valuable information.
When an exception is thrown, you can get the stack trace of where the exception happened which you can either print, or examine if you want to do some processing (so authentication errors for example, you may want to find out the method that called your internal function and log an error giving details of where the function was called from).
If you need help with exceptions, or perhaps you are confused with classes, struggling with Swing, or just tormented with templates we can guide you through any problems you may have. Java is a simple programming compared to C++ but it can have some rough edges that you need to consider, the worst is the memory leaks that occur when you have cyclic references.
In addition to tutoring services we also offer complete homework assignments, and not just in Java but in a wide range of programming languages. We can use tools such as TeamViewer to work along side you on your own computer.