diff --git a/lib/vcategories.php b/lib/vcategories.php
index 8de497a61917017d9e6b43a7f16abb3e6067a3a2..f94a0a55d3b904ad96c9b9ceeb31737002e8bb33 100644
--- a/lib/vcategories.php
+++ b/lib/vcategories.php
@@ -306,12 +306,18 @@ class OC_VCategories {
 			OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', OCP\Util::DEBUG);
 			return false;
 		}
-		OCP\DB::insertIfNotExist(self::CATEGORY_TABLE,
-			array(
-				'uid' => $this->user,
-				'type' => $this->type,
-				'category' => $name,
-			));
+		try {
+			OCP\DB::insertIfNotExist(self::CATEGORY_TABLE,
+				array(
+					'uid' => $this->user,
+					'type' => $this->type,
+					'category' => $name,
+				));
+			} catch(Exception $e) {
+				OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+					OCP\Util::ERROR);
+				return false;
+			}
 		$id = OCP\DB::insertid(self::CATEGORY_TABLE);
 		OCP\Util::writeLog('core', __METHOD__.', id: ' . $id, OCP\Util::DEBUG);
 		$this->categories[$id] = $name;
@@ -436,12 +442,17 @@ class OC_VCategories {
 	private function save() {
 		if(is_array($this->categories)) {
 			foreach($this->categories as $category) {
-				OCP\DB::insertIfNotExist(self::CATEGORY_TABLE,
-					array(
-						'uid' => $this->user,
-						'type' => $this->type,
-						'category' => $category,
-					));
+				try {
+					OCP\DB::insertIfNotExist(self::CATEGORY_TABLE,
+						array(
+							'uid' => $this->user,
+							'type' => $this->type,
+							'category' => $category,
+						));
+				} catch(Exception $e) {
+					OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+						OCP\Util::ERROR);
+				}
 			}
 			// reload categories to get the proper ids.
 			$this->loadCategories();
@@ -454,12 +465,17 @@ class OC_VCategories {
 				$catid = $this->array_searchi($relation['category'], $categories);
 				OC_Log::write('core', __METHOD__ . 'catid, ' . $relation['category'] . ' ' . $catid, OC_Log::DEBUG);
 				if($catid) {
-					OCP\DB::insertIfNotExist(self::RELATION_TABLE,
-						array(
-							'objid' => $relation['objid'],
-							'categoryid' => $catid,
-							'type' => $this->type,
-							));
+					try {
+						OCP\DB::insertIfNotExist(self::RELATION_TABLE,
+							array(
+								'objid' => $relation['objid'],
+								'categoryid' => $catid,
+								'type' => $this->type,
+								));
+					} catch(Exception $e) {
+						OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
+							OCP\Util::ERROR);
+					}
 				}
 			}
 			self::$relations = array(); // reset