diff --git a/compiler2/union.c b/compiler2/union.c
index e4f0603e0ab1870944955ba97fe9b29f81c863be..d7de465a19256196e6d3e49e1e1210f49aaa3bc3 100644
--- a/compiler2/union.c
+++ b/compiler2/union.c
@@ -2257,7 +2257,13 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
       src = mputstr(src,
         "    char* literal_str = mprintf(\"literal (%s)\",\n"
         "      (JSON_TOKEN_LITERAL_TRUE == j_token) ? \"true\" : \"false\");\n"
-        "    JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_AS_VALUE_ERROR, literal_str);\n"
+        "    try {\n"
+        "      JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_AS_VALUE_ERROR, literal_str);\n"
+        "    }\n"
+        "    catch (const TC_Error&) {\n"
+        "      Free(literal_str);\n"
+        "      throw;\n"
+        "    }\n"
         "    Free(literal_str);\n"
         "    clean_up();\n"
         "    return JSON_ERROR_FATAL;\n"
diff --git a/core/Addfunc.cc b/core/Addfunc.cc
index 8e3eaade1e227f1e3b6b8aa5735f02f39e82e7cc..c41f59b49117189ffa25488ad1979d42d49a0ee7 100644
--- a/core/Addfunc.cc
+++ b/core/Addfunc.cc
@@ -269,9 +269,14 @@ CHARSTRING int2char(const INTEGER& value)
   const int_val_t& ivt = value.get_val();
   if (ivt < 0 || ivt > 127) {
     char *value_str = ivt.as_string();
-    TTCN_error("The argument of function int2char() is %s, "
-      "which is outside the allowed range 0 .. 127.", value_str);
-    Free(value_str);
+    try {
+      TTCN_error("The argument of function int2char() is %s, "
+        "which is outside the allowed range 0 .. 127.", value_str);
+    }
+    catch (const TC_Error&) {
+      Free(value_str);
+      throw;
+    }
   }
   return CHARSTRING((char)((int)value));
 }
@@ -294,9 +299,14 @@ UNIVERSAL_CHARSTRING int2unichar(const INTEGER& value)
   const int_val_t& ivt = value.get_val();
   if (ivt < 0 || ivt > 2147483647) {
     char *value_str = ivt.as_string();
-    TTCN_error("The argument of function int2unichar() is %s, "
-      "which outside the allowed range 0 .. 2147483647.", value_str);
-    Free(value_str);
+    try {
+      TTCN_error("The argument of function int2unichar() is %s, "
+        "which outside the allowed range 0 .. 2147483647.", value_str);
+    }
+    catch (const TC_Error&) {
+      Free(value_str);
+      throw;
+    }
   }
   return int2unichar((int)value);
 }
@@ -310,9 +320,14 @@ BITSTRING int2bit(const INTEGER& value, int length)
   int_val_t tmp_value(value.get_val());
   if (tmp_value < 0) {
     char *value_str = tmp_value.as_string();
-    TTCN_error("The first argument (value) of function "
-      "int2bit() is a negative integer value: %s.", value_str);
-    Free(value_str);
+    try {
+      TTCN_error("The first argument (value) of function "
+        "int2bit() is a negative integer value: %s.", value_str);
+    }
+    catch (const TC_Error&) {
+      Free(value_str);
+      throw;
+    }
   }
   if (length < 0) TTCN_error("The second argument (length) of function "
     "int2bit() is a negative integer value: %d.", length);
@@ -333,10 +348,15 @@ BITSTRING int2bit(const INTEGER& value, int length)
       i++;
     }
     char *value_str = value.get_val().as_string(); // not tmp_value!
-    TTCN_error("The first argument of function int2bit(), which is %s, "
-      "does not fit in %d bit%s, needs at least %d.", value_str, length,
-      length > 1 ? "s" :"", length + i);
-    Free(value_str);
+    try {
+      TTCN_error("The first argument of function int2bit(), which is %s, "
+        "does not fit in %d bit%s, needs at least %d.", value_str, length,
+        length > 1 ? "s" :"", length + i);
+    }
+    catch (const TC_Error&) {
+      Free(value_str);
+      throw;
+    }
   }
   return ret_val;
 }
@@ -371,9 +391,14 @@ HEXSTRING int2hex(const INTEGER& value, int length)
   int_val_t tmp_value(value.get_val());
   if (value < 0) {
     char *value_str = tmp_value.as_string();
-    TTCN_error("The first argument (value) of function int2hex() is a "
-      "negative integer value: %s.", value_str);
-    Free(value_str);
+    try {
+      TTCN_error("The first argument (value) of function int2hex() is a "
+        "negative integer value: %s.", value_str);
+    }
+    catch (const TC_Error&) {
+      Free(value_str);
+      throw;
+    }
   }
   if (length < 0) TTCN_error("The second argument (length) of function "
     "int2hex() is a negative integer value: %d.", length);
@@ -388,10 +413,15 @@ HEXSTRING int2hex(const INTEGER& value, int length)
   }
   if (tmp_value != 0) {
     char *value_str = value.get_val().as_string(); // not tmp_value!
-    TTCN_error("The first argument of function int2hex(), which is %s, "
-      "does not fit in %d hexadecimal digit%s.", value_str, length,
-      length > 1 ? "s" :"");
-    Free(value_str);  // ???
+    try {
+      TTCN_error("The first argument of function int2hex(), which is %s, "
+        "does not fit in %d hexadecimal digit%s.", value_str, length,
+        length > 1 ? "s" :"");
+    }
+    catch (const TC_Error&) {
+      Free(value_str); 
+      throw;
+    }
   }
   return ret_val;
 }
diff --git a/regression_test/predefFunction2/.gitignore b/regression_test/predefFunction2/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..b904ff4e3337cb659b2b16c90efda642ff5b4e21
--- /dev/null
+++ b/regression_test/predefFunction2/.gitignore
@@ -0,0 +1,5 @@
+predefFunctTest
+predefFunctTest.exe
+predefFunctTest*.cc
+predefFunctTest*.hh
+predefFunctTest*.log