Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Context / Tizen.Context.AppHistory / AppHistoryErrorFactory.cs
1 /*
2  * Copyright (c) 2017 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 Tizen.Internals.Errors;
19
20 namespace Tizen.Context.AppHistory
21 {
22     internal enum AppHistoryError
23     {
24         None = ErrorCode.None,
25         InvalidParameter = ErrorCode.InvalidParameter,
26         OutOfMemory = ErrorCode.OutOfMemory,
27         PermissionDenied = ErrorCode.PermissionDenied,
28         NotSupported = ErrorCode.NotSupported,
29         NoData = ErrorCode.NoData,
30         OperationFailed = -0x02480000 | 0x04,
31     }
32
33     internal static class AppHistoryErrorFactory
34     {
35         internal const string LogTag = "Tizen.Context.AppHistory";
36
37         internal static Exception CheckAndThrowException(AppHistoryError error, string msg)
38         {
39             switch (error)
40             {
41                 case AppHistoryError.None:
42                     return null;
43                 case AppHistoryError.InvalidParameter:
44                     return new ArgumentException("Invalid Parameter: " + msg);
45                 case AppHistoryError.OutOfMemory:
46                     return new OutOfMemoryException("Out of Memory: " + msg);
47                 case AppHistoryError.PermissionDenied:
48                     return new UnauthorizedAccessException("Permission Denied: " + msg);
49                 case AppHistoryError.NotSupported:
50                     return new NotSupportedException("Not Supported: " + msg);
51                 case AppHistoryError.OperationFailed:
52                     return new InvalidOperationException("Operation Failed: " + msg);
53                 default:
54                     return new InvalidOperationException("Unknown Error Code: " + msg);
55             }
56         }
57     }
58 }