Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.System / Device / DeviceExceptionFactory.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.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21
22 namespace Tizen.System
23 {
24     internal enum DeviceError
25     {
26         None = Tizen.Internals.Errors.ErrorCode.None,
27         InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
28         PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
29         InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation,
30         AlreadyInProgress = Tizen.Internals.Errors.ErrorCode.NowInProgress,
31         NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,
32         ResourceBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy,
33         OperationFailed = -0x01140000 | 0x01,
34         NotInitialized = -0x01140000 | 0x02
35     };
36
37     class DeviceExceptionFactory
38     {
39         internal const string LogTag = "Tizen.System.Device";
40
41         internal static Exception CreateException(DeviceError err, string msg)
42         {
43             Exception exp;
44             switch (err)
45             {
46                 case DeviceError.InvalidParameter:
47                 case DeviceError.NotInitialized:
48                     //fall through
49                     exp =  new ArgumentException(msg);
50                     break;
51                 case DeviceError.NotSupported:
52                     exp = new NotSupportedException(msg +" : Device does not support the Operation.");
53                     break;
54                 case DeviceError.AlreadyInProgress:
55                     //fall through
56                 case DeviceError.ResourceBusy:
57                     //fall through
58                 case DeviceError.OperationFailed:
59                     //fall through
60                 case DeviceError.InvalidOperation:
61                     exp = new InvalidOperationException(msg);
62                     break;
63                 case DeviceError.PermissionDenied:
64                     exp = new UnauthorizedAccessException(msg);
65                     break;
66                 default:
67                     exp = new InvalidOperationException("Unknown error occured.");
68                     break;
69             }
70             return exp;
71         }
72     }
73 }