Home » Java Basics » exceptions

exceptions

java.lang.arrayindexoutofboundsexception – How to handle Array Index Out Of Bounds Exception

In this post, we feature a comprehensive Example on How to handle Array Index Out Of Bounds Exception. Java supports the creation and manipulation of arrays, as a data structure. A bunch of Java data structures are implemented using arrays to store and expand their data. Thus, arrays are massively used in programming, as they provide a very fast and ...

Read More »

java.lang.NullPointerException Example – How to handle Java Null Pointer Exception

In this post, we feature a comprehensive example of java.lang.NullPointerException – Java Null Pointer Exception. In Java, a special null value can be assigned to an object’s reference and denotes that the object is currently pointing to an unknown piece of data. A java.lang.NullPointerException is thrown when an application is trying to use or access an object whose reference equals to null. The following cases throw ...

Read More »

Java throw Exception Example

In this post, we feature a comprehensive Java throw Exception Example.  1. What is an Exception in Java? Exception is mechanism which Java uses to handle any unforeseen use-case/scenario. Basically an exception is thrown when either something unexpected happened during code execution which is not covered in any code block(converting some null value to lowercase()) or some IO operation communicating ...

Read More »

Create custom Exception example

This is an example of how to create and use a custom exception that will be thrown in a specified condition. In order to create a custom exception and use it in a method invocation we have followed the steps below: We have created an InvalidPassException class that extends the Exception and uses the Exception’s constructors in its constructors.  We have ...

Read More »

Checked and Unchecked Exceptions example

In this example we shall show you how to use a checked and an unchecked exception. A checked exception is anything that is a subclass of Exception, except for RuntimeException and its subclasses. In order to use a checked and an unchecked exception we have followed the steps below: We have created a method, void checkSize(String fileName) that creates a ...

Read More »