# Do not throw on Key not found

**URL:** <https://discuss.aerospike.com/t/do-not-throw-on-key-not-found/10105>\
**Category:** C# Client\
**Created:** [March 27, 2023, 4:03pm UTC](https://discuss.aerospike.com/t/do-not-throw-on-key-not-found/10105 "2023-03-27T16:03:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adesmoules](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/adesmoules/32/2051_2.png) [@adesmoules](https://discuss.aerospike.com/u/adesmoules)\
**Post date:** [March 27, 2023, 4:03pm UTC](https://discuss.aerospike.com/t/do-not-throw-on-key-not-found/10105/1 "2023-03-27T16:03:56Z")

</div>

Hi,

I’m currently using the Aerospike C# client and when i try to call Put on a non existing Record, the client is throwing an Exception.

Is there a way to avoid to throw an Exception in a write operation (either Put or Operate) when the record doesn’t exit and just ignore it ?

The only solution i found for now is to use a UDF, but it’s overengineered imho.

Regards,

---

<div class="post-metadata">

**Author:** ![meher](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/meher/32/1644_2.png) [@meher](https://discuss.aerospike.com/u/meher)\
**Post date:** [March 28, 2023, 3:59pm UTC](https://discuss.aerospike.com/t/do-not-throw-on-key-not-found/10105/2 "2023-03-28T15:59:20Z")

</div>

By put on an existing record are you referring to add elements to a map or list? I see some example on this tutorial: [Aerospike Interactive Tutorial: Advanced Collection Data Types | Developer](https://developer.aerospike.com/tutorials/java/java-advanced_collection_data_types) .

If you are referring to updating an existing record (like adding a bin) there are also different policies. Here is a page with some details: [Update a Record | Developer](https://developer.aerospike.com/client/usage/atomic/update#policies).

---

<div class="post-metadata">

**Author:** ![adesmoules](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/adesmoules/32/2051_2.png) [@adesmoules](https://discuss.aerospike.com/u/adesmoules)\
**Post date:** [March 28, 2023, 4:24pm UTC](https://discuss.aerospike.com/t/do-not-throw-on-key-not-found/10105/3 "2023-03-28T16:24:18Z")

</div>

I’d like to [update a bin](https://developer.aerospike.com/client/usage/atomic/update#update-a-record) with an `UPDATE_ONLY` policy as I don’t want to create the record if not already present.

If the record doesn’t exist, an exception is thrown by the client, but catching the exception would be too costly in my case (high load environment).

---

<div class="post-metadata">

**Author:** ![Brian](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/brian/32/2211_2.png) [@Brian](https://discuss.aerospike.com/u/Brian)\
**Post date:** [March 28, 2023, 9:36pm UTC](https://discuss.aerospike.com/t/do-not-throw-on-key-not-found/10105/5 "2023-03-28T21:36:04Z")

</div>

Other than using a UDF, the exception is unavoidable if `UPDATE_ONLY` is used and the record does not exist.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [June 20, 2023, 9:36pm UTC](https://discuss.aerospike.com/t/do-not-throw-on-key-not-found/10105/7 "2023-06-20T21:36:19Z")

</div>

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