Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Alarm / Tizen.Applications / AlarmErrorFactory.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
19 namespace Tizen.Applications
20 {
21     internal enum AlarmError
22     {
23         None = Tizen.Internals.Errors.ErrorCode.None,
24         InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
25         InvalidTime = -0x01100000 | 0x05,
26         InvalidDate = -0x01100000 | 0x06,
27         ConnectionFail = -0x01100000 | 0x07,
28         NotPermittedApp = -0x01100000 | 0x08,
29         OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
30         PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied
31     }
32     internal static class AlarmErrorFactory
33     {
34         private const string _logTag = "Tizen.Applications.Alarm";
35
36         internal static Exception GetException(AlarmError ret, string msg)
37         {
38             switch (ret)
39             {
40                 case AlarmError.InvalidParameter:
41                 //fall through
42                 case AlarmError.InvalidTime:
43                 //fall through
44                 case AlarmError.InvalidDate:
45                     Log.Error(_logTag, msg);
46                     return new ArgumentException(ret + " error occurred.");
47                 case AlarmError.NotPermittedApp:
48                 //fall through
49                 case AlarmError.PermissionDenied:
50                     Log.Error(_logTag, msg);
51                     return new UnauthorizedAccessException(ret + "error occured.");
52                 default:
53                     Log.Error(_logTag, msg);
54                     return new InvalidOperationException(ret + " error occurred.");
55             }
56         }
57     }
58 }