# How to instantiate class from with class.forName()

**URL:** https://discourse.processing.org/t/how-to-instantiate-class-from-with-class-forname/957
**Category:** Coding Questions
**Created:** [June 14, 2018, 11:26am UTC](https://discourse.processing.org/t/how-to-instantiate-class-from-with-class-forname/957 "2018-06-14T11:26:53Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![noahbuddy](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@noahbuddy](https://discourse.processing.org/u/noahbuddy)
#### Post date: [June 15, 2018, 4:13am UTC](https://discourse.processing.org/t/how-to-instantiate-class-from-with-class-forname/957/2 "2018-06-15T04:13:28Z")

</div>

> Unhandled exception type ClassNotFoundException

That means the compiler is expecting you to surround the class loading function(s) with an exception handling block. Namely, the [try and catch](https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html) blocks.

At a minimum, you could do something like this:

```
try {
  // load class by name, etc.
}
catch(Exception ex)
{
  println("Something went wrong");
  println(ex.toString());
}

```

Of course, that will print the same message (plus the built-in) for _any_ error.

The message you are getting is calling out for something more like this:

```
try {
  // load class by name, etc.
}
catch(ClassNotFoundException ex)
{
  println("Class not found");
}
catch(IllegalAccessException ex)
{
  println("Do you have permission for that?");
}
catch(InstantiationException ex)
{
  println("Could not instantiate object");
}

```

It is up to you how much detail you want from the exception handling.

For more, take a look at [Lesson: Exceptions (The Java™ Tutorials \> Essential Java Classes)](https://docs.oracle.com/javase/tutorial/essential/exceptions/)

---

_[View the full topic](https://discourse.processing.org/t/how-to-instantiate-class-from-with-class-forname/957)._
