2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Diagnostics;
20 using Tizen.Internals.Errors;
22 namespace Tizen.Multimedia.Util
25 internal enum ImageUtilError
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,
37 internal static class ImageUtilErrorExtensions
39 internal static void ThrowIfFailed(this ImageUtilError err, string message)
41 if (err == ImageUtilError.None)
46 throw err.ToException(message);
49 internal static Exception ToException(this ImageUtilError err, string message)
51 Debug.Assert(err != ImageUtilError.None);
53 string errMessage = $"{message}; {err}.";
56 case ImageUtilError.PermissionDenied:
57 return new UnauthorizedAccessException(errMessage);
59 case ImageUtilError.InvalidParameter:
60 return new ArgumentException(errMessage);
62 case ImageUtilError.NoSuchFile:
63 return new FileNotFoundException(errMessage);
65 case ImageUtilError.OutOfMemory:
66 return new OutOfMemoryException(errMessage);
68 case ImageUtilError.NotSupported:
69 return new NotSupportedException(errMessage);
71 case ImageUtilError.NotSupportedFormat:
72 return new FileFormatException(errMessage);
74 case ImageUtilError.InvalidOperation:
76 return new InvalidOperationException(errMessage);