Add Tizen.Peripheral API (#1939)
[platform/core/csapi/tizenfx.git] / internals / src / Tizen.Peripheral / Tizen.Peripheral / ExceptionFactory.cs
1 /*
2 * Copyright (c) 2020 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.Peripheral
21 {
22     /// <summary>
23     /// The class that represents the exception which will be thrown when the application can not control the peripherial.
24     /// </summary>
25     internal static class ExceptionFactory
26     {
27         internal static Exception CreateException(ErrorCode errorCode)
28         {
29             Log.Error("Peripheral", $"Error {errorCode}");
30
31             switch (errorCode)
32             {
33                 case ErrorCode.IoError:
34                     return new InvalidOperationException("I/O Error occured");
35
36                 case ErrorCode.NoSuchDevice:
37                     return new InvalidOperationException("No such device");
38
39                 case ErrorCode.TryAgain:
40                     return new InvalidOperationException("Try again");
41
42                 case ErrorCode.OutOfMemory:
43                     return new Exception("Out of memory");
44
45                 case ErrorCode.PermissionDenied:
46                     return new UnauthorizedAccessException("Permission denied");
47
48                 case ErrorCode.ResourceBusy:
49                     return new InvalidOperationException("Resource is busy");
50
51                 case ErrorCode.InvalidParameter:
52                     return new ArgumentException("Invalid parameters provided");
53
54                 case ErrorCode.NotSupported:
55                     return new InvalidOperationException("I/O Error occured");
56
57                 case ErrorCode.Unknown:
58                     return new InvalidOperationException("Unknown exception");
59
60                 default:
61                     return new Exception("");
62             }
63         }
64     }
65 }