Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Radio / Radio / RadioError.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 Tizen.Internals.Errors;
19
20 namespace Tizen.Multimedia
21 {
22
23     internal enum RadioError
24     {
25         None = ErrorCode.None,
26         OutOfMemory = ErrorCode.OutOfMemory,
27         InvalidParameter = ErrorCode.InvalidParameter,
28         InvalidOperation = ErrorCode.InvalidOperation,
29         PermissionDenied = ErrorCode.PermissionDenied,
30         NotSupported = ErrorCode.NotSupported,
31
32         InvalidState = -0x019A0000 | 0x01,
33         SoundPolicy = -0x019A0000 | 0x02,
34         NoAntenna = -0x019A0000 | 0x03,
35     }
36
37     internal static class RadioErrorExtensions
38     {
39         internal static void ThrowIfFailed(this RadioError err, string message)
40         {
41             if (err == RadioError.None)
42             {
43                 return;
44             }
45
46             string errMessage = $"{message}; {err}.";
47             switch (err)
48             {
49                 case RadioError.PermissionDenied:
50                     throw new UnauthorizedAccessException(errMessage);
51
52                 case RadioError.InvalidParameter:
53                     throw new ArgumentException(errMessage);
54
55                 case RadioError.OutOfMemory:
56                     throw new OutOfMemoryException(errMessage);
57
58                 case RadioError.NotSupported:
59                 case RadioError.NoAntenna:
60                     throw new NotSupportedException(errMessage);
61
62                 default:
63                     throw new InvalidOperationException(errMessage);
64             }
65         }
66
67     }
68
69 }