2 * Copyright (c) 2017 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.Runtime.CompilerServices;
20 namespace Tizen.Applications.DataControl
22 internal static class ErrorFactory
24 private const string LogTag = "Tizen.Applications.DataControl";
26 internal static void ThrowException(ResultType errorCode, bool ignoreType, string errorMessage = null,
27 [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0)
29 Log.Error(LogTag, $"{memberName}({lineNumber.ToString()}) : {filePath}");
32 throw new InvalidOperationException(string.IsNullOrEmpty(errorMessage) ? "error code : " + errorCode.ToString() :
33 $"{errorMessage} - {errorCode}");
38 case ResultType.Success:
40 case ResultType.OutOfMemory:
41 case ResultType.IoError:
42 throw new InvalidOperationException(string.IsNullOrEmpty(errorMessage) ? "error code : " + errorCode.ToString() :
43 $"{errorMessage} - {errorCode}");
44 case ResultType.InvalidParameter:
45 Log.Error(LogTag, "Invalid parameter : " + errorMessage);
46 throw new ArgumentException(string.IsNullOrEmpty(errorMessage) ? "Invalid parameter" : "Invalid parameter : " + errorMessage);
47 case ResultType.PermissionDenied:
48 Log.Error(LogTag, "Permission denied : " + errorMessage);
49 throw new UnauthorizedAccessException(string.IsNullOrEmpty(errorMessage) ? "Permission denied" : "Permission denied : " + errorMessage);
50 case ResultType.MaxExceed:
51 Log.Error(LogTag, "Too long argument : " + errorMessage);
52 throw new ArgumentOutOfRangeException(string.IsNullOrEmpty(errorMessage) ? "Too long argument" : "Too long argument : " + errorMessage);
54 Log.Error(LogTag, $"Unknown error : {errorMessage} - {errorCode}");
55 throw new InvalidOperationException(string.IsNullOrEmpty(errorMessage) ? "Unknown error : " + errorCode.ToString() :
56 $"Unknown error : {errorMessage} - {errorCode}");