Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Util / ImageUtil / ImageUtilError.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Diagnostics;
19 using System.IO;
20 using Tizen.Internals.Errors;
21
22 namespace Tizen.Multimedia.Util
23 {
24
25     internal enum ImageUtilError
26     {
27         None = ErrorCode.None,
28         OutOfMemory = ErrorCode.OutOfMemory,
29         InvalidParameter = ErrorCode.InvalidParameter,
30         InvalidOperation = ErrorCode.InvalidOperation,
31         PermissionDenied = ErrorCode.PermissionDenied,
32         NotSupported = ErrorCode.NotSupported,
33         NoSuchFile = ErrorCode.NoSuchFile,
34         NotSupportedFormat = -0x01920000 | 0x01,
35     }
36
37     internal static class ImageUtilErrorExtensions
38     {
39         internal static void ThrowIfFailed(this ImageUtilError err, string message)
40         {
41             if (err == ImageUtilError.None)
42             {
43                 return;
44             }
45
46             throw err.ToException(message);
47         }
48
49         internal static Exception ToException(this ImageUtilError err, string message)
50         {
51             Debug.Assert(err != ImageUtilError.None);
52
53             string errMessage = $"{message}; {err}.";
54             switch (err)
55             {
56                 case ImageUtilError.PermissionDenied:
57                     return new UnauthorizedAccessException(errMessage);
58
59                 case ImageUtilError.InvalidParameter:
60                     return new ArgumentException(errMessage);
61
62                 case ImageUtilError.NoSuchFile:
63                     return new FileNotFoundException(errMessage);
64
65                 case ImageUtilError.OutOfMemory:
66                     return new OutOfMemoryException(errMessage);
67
68                 case ImageUtilError.NotSupported:
69                     return new NotSupportedException(errMessage);
70
71                 case ImageUtilError.NotSupportedFormat:
72                     return new FileFormatException(errMessage);
73
74                 case ImageUtilError.InvalidOperation:
75                 default:
76                     return new InvalidOperationException(errMessage);
77             }
78         }
79     }
80
81 }