Make exception safe codes (#2588)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Mon, 1 Feb 2021 02:52:00 +0000 (11:52 +0900)
committerGitHub <noreply@github.com>
Mon, 1 Feb 2021 02:52:00 +0000 (11:52 +0900)
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.Common/Tizen.Applications/ApplicationManager.cs

index 64969c70f73160e4b7dc68be31a943c4a9e7609d..4a3e0322df45059beac5b1b4f11d99b33671949d 100755 (executable)
@@ -196,7 +196,7 @@ namespace Tizen.Applications
                 err = Interop.ApplicationManager.AppManagerForeachAppInfo(cb, IntPtr.Zero);
                 if (err != Interop.ApplicationManager.ErrorCode.None)
                 {
-                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to foreach the appinfo.");
+                    Log.Error(LogTag, "Failed to retrieve the application Info. err " + err.ToString());
                 }
                 return result;
             }).ConfigureAwait(false);
@@ -261,7 +261,20 @@ namespace Tizen.Applications
                     }
                     return false;
                 };
-                filter.Fetch(cb);
+
+                try
+                {
+                    filter.Fetch(cb);
+                }
+                catch (InvalidOperationException)
+                {
+                    Log.Error(LogTag, "InvalidOperationException occurs");
+                }
+                catch (ArgumentException)
+                {
+                    Log.Error(LogTag, "ArgumentException occurs");
+                }
+
                 return result;
             }).ConfigureAwait(false);
         }
@@ -295,7 +308,20 @@ namespace Tizen.Applications
                     }
                     return false;
                 };
-                filter.Fetch(cb);
+
+                try
+                {
+                    filter.Fetch(cb);
+                }
+                catch (InvalidOperationException)
+                {
+                    Log.Error(LogTag, "InvalidOperationException occurs");
+                }
+                catch (ArgumentException)
+                {
+                    Log.Error(LogTag, "ArgumentException occurs");
+                }
+
                 return result;
             }).ConfigureAwait(false);
         }
@@ -333,7 +359,7 @@ namespace Tizen.Applications
                 err = Interop.ApplicationManager.AppManagerForeachAppContext(cb, IntPtr.Zero);
                 if (err != Interop.ApplicationManager.ErrorCode.None)
                 {
-                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to foreach appcontext.");
+                    Log.Error(LogTag, "Failed to retrieve the running app context. err " + err.ToString());
                 }
                 return result;
             }).ConfigureAwait(false);
@@ -372,7 +398,7 @@ namespace Tizen.Applications
                 err = Interop.ApplicationManager.AppManagerForeachRunningAppContext(cb, IntPtr.Zero);
                 if (err != Interop.ApplicationManager.ErrorCode.None)
                 {
-                    throw ApplicationManagerErrorFactory.GetException(err, "Failed to foreach appcontext.");
+                    Log.Error(LogTag, "Failed to retrieve the running app context. err " + err.ToString());
                 }
                 return result;
             }).ConfigureAwait(false);