[MediaContent] Added exception handling to catch p/invoke error return (#367)
authorhsgwon <haesu.gwon@samsung.com>
Mon, 6 Aug 2018 09:38:57 +0000 (18:38 +0900)
committerGitHub <noreply@github.com>
Mon, 6 Aug 2018 09:38:57 +0000 (18:38 +0900)
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/PlaylistCommand.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/StorageCommand.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/TagCommand.cs

index 04a4a71..2ca384d 100644 (file)
@@ -239,13 +239,13 @@ namespace Tizen.Content.MediaContent
             {
                 Interop.Playlist.GetPlaylistFromDb(playlistId, out handle).ThrowIfError("Failed to query");
 
-                if (handle == IntPtr.Zero)
-                {
-                    throw new RecordNotFoundException("No matching playlist exists.");
-                }
-
                 Interop.Playlist.ExportToFile(handle, path).ThrowIfError("Failed to export");
             }
+            catch (ArgumentException)
+            {
+                // Native FW returns ArgumentException when there's no matched record.
+                throw new RecordNotFoundException("No matching playlist exists.");
+            }
             finally
             {
                 if (handle != IntPtr.Zero)
@@ -381,13 +381,13 @@ namespace Tizen.Content.MediaContent
             {
                 Interop.Playlist.GetPlaylistFromDb(playlistId, out handle).ThrowIfError("Failed to query");
 
-                if (handle == IntPtr.Zero)
-                {
-                    return null;
-                }
-
                 return new Playlist(handle);
             }
+            catch (ArgumentException)
+            {
+                // Native FW returns ArgumentException when there's no matched record.
+                return null;
+            }
             finally
             {
                 if (handle != IntPtr.Zero)
index f0b4992..2d91c36 100644 (file)
@@ -88,7 +88,12 @@ namespace Tizen.Content.MediaContent
             {
                 Interop.Storage.GetStorageInfoFromDb(storageId, out handle).ThrowIfError("Failed to query");
 
-                return handle == IntPtr.Zero ? null : new Storage(handle);
+                return new Storage(handle);
+            }
+            catch (ArgumentException)
+            {
+                // Native FW returns ArgumentException when there's no matched record.
+                return null;
             }
             finally
             {
index 0d82b53..6cb6b7d 100644 (file)
@@ -213,12 +213,13 @@ namespace Tizen.Content.MediaContent
             {
                 Interop.Tag.GetTagFromDb(tagId, out handle).ThrowIfError("Failed to query");
 
-                if (handle == IntPtr.Zero)
-                {
-                    return null;
-                }
                 return new Tag(handle);
             }
+            catch (ArgumentException)
+            {
+                // Native FW returns ArgumentException when there's no matched record.
+                return null;
+            }
             finally
             {
                 if (handle != IntPtr.Zero)