# Invoke code:

**URL:** <https://forum.uipath.com/t/invoke-code/564550>\
**Category:** Studio\
**Tags:** activities-panel, question, studio, system, activities\
**Created:** [July 19, 2023, 6:23am UTC](https://forum.uipath.com/t/invoke-code/564550 "2023-07-19T06:23:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpho.ndoweni](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mpho.ndoweni/32/264548_2.png) [@mpho.ndoweni](https://forum.uipath.com/u/mpho.ndoweni)\
**Post date:** [July 19, 2023, 6:23am UTC](https://forum.uipath.com/t/invoke-code/564550/1 "2023-07-19T06:23:35Z")

</div>

Hi Guys may you kindly please assist me i am using invoke code to loop through datatables compare values and add to another datatable but i get an error Invoke Code: Exception has been thrown by the target of an invocation.

 ![InvokeCode](https://global.discourse-cdn.com/uipath/original/4X/8/1/c/81cd9a2a521a6535f864f08c3e5580b7fea0c043.png)  
 ![Arguments](https://global.discourse-cdn.com/uipath/original/4X/7/b/0/7b050bb5d0454832f2674c9719e5c60cfe4fb4e9.png)

---

<div class="post-metadata">

**Author:** ![Vikas\_M](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/vikas_m/32/411569_2.png) [@Vikas\_M](https://forum.uipath.com/u/Vikas_M)\
**Post date:** [July 19, 2023, 6:25am UTC](https://forum.uipath.com/t/invoke-code/564550/2 "2023-07-19T06:25:46Z")

</div>

Hey @mpho.ndoweni ,  
Can Check for null value… Ensure that you are handling null or empty values properly  
Also its better to Add exception handling…Surround the code inside the “Invoke Code” activity with a Try-Catch block. This way, you can catch any exceptions and log the specific error message for debugging.  
Use a `Write Line` or Log the exception message or direct the exception to an out argument such that we can handle the Exception in a better way.

Based on the Exception message we can understand the issue being faced.

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [July 19, 2023, 6:27am UTC](https://forum.uipath.com/t/invoke-code/564550/3 "2023-07-19T06:27:18Z")

</div>

Hi,

> [@mpho.ndoweni](#):
>
> Exception has been thrown by the target of an invocation.

For now can you check content of $ExceptionDetails in Locals panel when error occurs in debug mode? Probably there is detailed information for the exception.

Regards,

---

<div class="post-metadata">

**Author:** ![mpho.ndoweni](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mpho.ndoweni/32/264548_2.png) [@mpho.ndoweni](https://forum.uipath.com/u/mpho.ndoweni)\
**Post date:** [July 19, 2023, 7:26am UTC](https://forum.uipath.com/t/invoke-code/564550/4 "2023-07-19T07:26:21Z")

</div>

Hey thanks it appears the error occurs when i declare a new row on dim newrow As DataRow = out\_dt\_nedbank\_comapare.NewRow

---

<div class="post-metadata">

**Author:** ![mpho.ndoweni](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mpho.ndoweni/32/264548_2.png) [@mpho.ndoweni](https://forum.uipath.com/u/mpho.ndoweni)\
**Post date:** [July 19, 2023, 7:27am UTC](https://forum.uipath.com/t/invoke-code/564550/5 "2023-07-19T07:27:27Z")

</div>

Hey Thanks yes it appears the error occurs when i declare new row

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [July 19, 2023, 7:28am UTC](https://forum.uipath.com/t/invoke-code/564550/6 "2023-07-19T07:28:36Z")

</div>

HI,

Can you share whole content of $excceptionDetails?

Regards,

---

<div class="post-metadata">

**Author:** ![Vikas\_M](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/vikas_m/32/411569_2.png) [@Vikas\_M](https://forum.uipath.com/u/Vikas_M)\
**Post date:** [July 19, 2023, 7:48am UTC](https://forum.uipath.com/t/invoke-code/564550/7 "2023-07-19T07:48:37Z")

</div>

Ohh,Also Surround the code using Try catch for best practices!

Happy Automation! 🙂

---

<div class="post-metadata">

**Author:** ![mpho.ndoweni](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mpho.ndoweni/32/264548_2.png) [@mpho.ndoweni](https://forum.uipath.com/u/mpho.ndoweni)\
**Post date:** [July 19, 2023, 8:00am UTC](https://forum.uipath.com/t/invoke-code/564550/8 "2023-07-19T08:00:45Z")

</div>

![Exception](https://global.discourse-cdn.com/uipath/original/4X/d/5/3/d53387be2c5121080d921e3a9e1ae03236fb9d10.png)

 ![AnotherExcept](https://global.discourse-cdn.com/uipath/original/4X/d/3/3/d330f4a1e7f873dbb60de3235fb76d9356abb73a.png)

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [July 19, 2023, 8:05am UTC](https://forum.uipath.com/t/invoke-code/564550/9 "2023-07-19T08:05:19Z")

</div>

Hi,

I guess out\_dt\_nedbank\_compare is null. So can you try to add either of the following expression at the beginning of the code?

```
out_dt_nedbank_compare = in_dt_nedbank.Clone

```

OR

```
out_dt_nedbank_compare = in_Dt_Comparison.Clone

```

Regards,

---

<div class="post-metadata">

**Author:** ![mpho.ndoweni](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mpho.ndoweni/32/264548_2.png) [@mpho.ndoweni](https://forum.uipath.com/u/mpho.ndoweni)\
**Post date:** [July 19, 2023, 8:29am UTC](https://forum.uipath.com/t/invoke-code/564550/10 "2023-07-19T08:29:39Z")

</div>

Thank you so much Yoichi it is now working

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [July 22, 2023, 8:30am UTC](https://forum.uipath.com/t/invoke-code/564550/11 "2023-07-22T08:30:19Z")

</div>

Closed on July 22, 2023, 8:30am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
