# Try/catch failing for InvalidArgumentException

**URL:** <https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264>\
**Category:** General\
**Created:** [February 7, 2019, 7:04am UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264 "2019-02-07T07:04:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [February 7, 2019, 7:04am UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/1 "2019-02-07T07:04:05Z")

</div>

Got an error report from a user regarding an InvalidArgumentException

[quote]2019-02-04, 2:25:38 PM Class/Method: MimeImagePreview.MakeImagePreview  
2019-02-04, 2:25:38 PM Time: Monday, February 4, 2019 2:25:38 PM 3565554  
2019-02-04, 2:25:38 PM Type of Error: InvalidArgumentException[/quote]

To check what the problem is I wrapped the code with a try/catch:

` try
    dim image as new GMImageMBS(PreviewPic)
    image.autoOrient
    PreviewPic = image.CopyPicture(0, 0, image.columns, image.rows)
  catch err as InvalidArgumentException
    Globals.theAppLog.AddToAppLog("InvalidArgumentException for " + App.MailFields.MainSubject, "")
  end try`

But why does Xojo tell me: “Can’t find a type with this name. Did you mean Xojo.Core.InvalidArgumentException?” Xojo 2018r3, High Sierra.

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [February 7, 2019, 7:49am UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/2 "2019-02-07T07:49:52Z")

</div>

Possibly because it is in the new framework but not the old one?

Have you tried

```auto
Catch err as Xojo,Core.InvalidArgumentException
```

Have you tried if Application.UnhandledException catches it?

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [February 7, 2019, 8:13am UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/3 "2019-02-07T08:13:56Z")

</div>

The docs says it’s an InvalidArgumentException and not a Xojo.Core one: [http://documentation.xojo.com/api/exceptions/invalidargumentexception.html](http://documentation.xojo.com/api/exceptions/invalidargumentexception.html)

I also don’t think that Christian’s code does a Xojo.core exceptions anywhere.

I get the type with Introspection, which should give me the correct type

`dim ErrorInfo as Introspection.TypeInfo = Introspection.GetType(theError)
dim theResult as String = ErrorInfo.Name`

App.UnhandledException is a no-go because I have a dedicated error handling routine. UnhandledException doesn’t work in a thread anyways.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [February 7, 2019, 8:14am UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/4 "2019-02-07T08:14:50Z")

</div>

And a bare

`try
catch err as InvalidArgumentException
end try
`  
also doesn’t work and gives the same error.

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [February 7, 2019, 8:39am UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/5 "2019-02-07T08:39:43Z")

</div>

[quote=424053:@Beatrix Willius]The docs says it’s an InvalidArgumentException and not a Xojo.Core one: [http://documentation.xojo.com/api/exceptions/invalidargumentexception.html](http://documentation.xojo.com/api/exceptions/invalidargumentexception.html)

I also don’t think that Christian’s code does a Xojo.core exceptions anywhere.[/quote]

Right, and as we all know there are no errors in the documentation, and Xojo works exactly as the documentation says.

Even though the compiler says thats where the problem is?

Wouldnt it be easier to just try

```auto
Catch err as Xojo,Core.InvalidArgumentException
```

rather than explain why that shouldnt work?

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [February 7, 2019, 9:21am UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/6 "2019-02-07T09:21:01Z")

</div>

The Xojo.Core exception won’t work because it’s not the correct type. It’s a bug somewhere in Christian’s code anyways. I’ll get the data from the user first.

I reported the bug at \<[https://xojo.com/issue/54863](https://xojo.com/issue/54863)\> .

---

<div class="post-metadata">

**Author:** ![Jon\_Eisen](https://forum.xojo.com/user_avatar/forum.xojo.com/jon_eisen/32/247_2.png) [@Jon\_Eisen](https://forum.xojo.com/u/Jon_Eisen)\
**Post date:** [February 7, 2019, 7:12pm UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/7 "2019-02-07T19:12:03Z")

</div>

> [@424053:@Beatrix Willius](#):
>
> The docs says it’s an InvalidArgumentException and not a Xojo.Core one: [InvalidArgumentException — Xojo documentation](http://documentation.xojo.com/api/exceptions/invalidargumentexception.html)

If you follow the documentation link, it redirects to Xojo.Core.InvalidArgumentException and the IDE gives me a compilation error:

`Can't find a type with this name. Did you mean class Xojo.Core.InvalidArgumentException?
Catch err As InvalidArgumentException`

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [February 8, 2019, 11:44am UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/8 "2019-02-08T11:44:16Z")

</div>

Turns out that there is no InvalidArgumentException, only a Xojo.Core.InvalidArgumentException and the documentation was already updated. Introspection has a FullName in addition to the Name property, which I don’t think is a good idea. But whatever. I can now send something to my user.

---

<div class="post-metadata">

**Author:** ![Jon\_Eisen](https://forum.xojo.com/user_avatar/forum.xojo.com/jon_eisen/32/247_2.png) [@Jon\_Eisen](https://forum.xojo.com/u/Jon_Eisen)\
**Post date:** [February 8, 2019, 5:12pm UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/9 "2019-02-08T17:12:52Z")

</div>

> [@424163:@Beatrix Willius](#):
>
> Introspection has a FullName in addition to the Name property

I’m willing to bet this is related to the class structure under the hood utilizing modules and such. The framework needs to know the object name but can then calculate the FullName using the object name and the parent namespace.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:33pm UTC](https://forum.xojo.com/t/try-catch-failing-for-invalidargumentexception/47264/10 "2020-10-29T19:33:01Z")

</div>


