# Question for "try()"

**URL:** <https://discourse.processing.org/t/question-for-try/24151>\
**Category:** Beginners\
**Created:** [September 27, 2020, 11:43am UTC](https://discourse.processing.org/t/question-for-try/24151 "2020-09-27T11:43:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoLi](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JoLi](https://discourse.processing.org/u/JoLi)\
**Post date:** [September 27, 2020, 11:43am UTC](https://discourse.processing.org/t/question-for-try/24151/1 "2020-09-27T11:43:56Z")

</div>

Any Ideas, why this is not working?  
 ![grafik](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c066ba82fd17d778f96cf62c84484387fb0805d2.png)

Processing 3.5.4, Windows 10

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 27, 2020, 2:08pm UTC](https://discourse.processing.org/t/question-for-try/24151/2 "2020-09-27T14:08:37Z")

</div>

Hello,

There is a statement here about the error that is returned:  
[https://processing.org/reference/loadStrings\_.html](https://processing.org/reference/loadStrings_.html)

I ended up checking for a _null_.

If I tried to:

> println(test)

I did get an expected:

> NullPointerExeption

My exploration into this without a save.txt file to load:

```auto
String[] test;

void setup() 
	{
  size(200, 200);
  
  try
    {
    println("Try");
    test = loadStrings("save.txt");
    if (test == null)
      {
      println("null");
      //println(test); // This generates a NullPointerExeption !
      }
    }
  catch (Exception e)
    {
    println("Catch");  
    println(e);
    }	
  }

void draw() 
	{
  background(255);
	}

```

`:)`

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 27, 2020, 4:48pm UTC](https://discourse.processing.org/t/question-for-try/24151/3 "2020-09-27T16:48:10Z")

</div>

In Java most file access methods will throw exceptions including the `IOException` when things go wrong.

In the Processing source code, methods like `loadStrings` wraps includes all the Java file handling statements, these methods include try-catch statements to catch any exceptions thrown by Java, in that situation the Processing method will probably return `null`.

This is what happens inside `loadStrings` if a Java exception is thrown when executing the method it simply captures the exception and returns null. This means the user does not need to understand or use the try-catch syntax.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 27, 2020, 5:31pm UTC](https://discourse.processing.org/t/question-for-try/24151/4 "2020-09-27T17:31:10Z")

</div>

> [@quark](#):
>
> In the Processing source code, methods like `loadStrings` wraps includes all the Java file handling statements, these methods include try-catch statements to catch any exceptions thrown by Java, in that situation the Processing method will probably return `null` .

Can you please show me where in the source code?

I will probably look this up as well.  
You may have more experience navigating in there.

`:)`

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 28, 2020, 11:10am UTC](https://discourse.processing.org/t/question-for-try/24151/5 "2020-09-28T11:10:59Z")

</div>

This links to the [source code](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java). Scroll done to line 7567 for the `loadStrings(String)` method which accepts a String representing the filename.
