csapi-sensor: update API spec about exceptions
[platform/core/csapi/sensor.git] / Tizen.Sensor / Tizen.Sensor / SensorErrorFactory.cs
1 // Copyright 2016 by Samsung Electronics, Inc.,
2 //
3 // This software is the confidential and proprietary information
4 // of Samsung Electronics, Inc. ("Confidential Information"). You
5 // shall not disclose such Confidential Information and shall use
6 // it only in accordance with the terms of the license agreement
7 // you entered into with Samsung.
8
9 using System;
10 using Tizen.Internals.Errors;
11
12 namespace Tizen.Sensor
13 {
14     internal enum SensorError
15     {
16         None = ErrorCode.None,
17         IOError = ErrorCode.IoError,
18         InvalidParameter = ErrorCode.InvalidParameter,
19         NotSupported = ErrorCode.NotSupported,
20         PermissionDenied = ErrorCode.PermissionDenied,
21         OutOfMemory = ErrorCode.OutOfMemory,
22         NotNeedCalibration = -0x02440000 | 0x03,
23         OperationFailed = -0x02440000 | 0x06
24     }
25
26     internal static class SensorErrorFactory
27     {
28         static internal Exception CheckAndThrowException(int error, string msg)
29         {
30             SensorError e = (SensorError)error;
31             switch (e)
32             {
33                 case SensorError.None:
34                     return null;
35                 case SensorError.IOError:
36                     return new InvalidOperationException("I/O Error: " + msg);
37                 case SensorError.InvalidParameter:
38                     return new ArgumentException("Invalid Parameter: " + msg);
39                 case SensorError.NotSupported:
40                     return new NotSupportedException("Not Supported: " + msg);
41                 case SensorError.PermissionDenied:
42                     return new UnauthorizedAccessException("Permission Denied: " + msg);
43                 case SensorError.OutOfMemory:
44                     return new InvalidOperationException("Out of Memory: " + msg);
45                 case SensorError.NotNeedCalibration:
46                     return new InvalidOperationException("Sensor doesn't need calibration: " + msg);
47                 case SensorError.OperationFailed:
48                     return new InvalidOperationException("Operation Failed: " + msg);
49                 default:
50                     return new InvalidOperationException("Unknown Error Code: " + msg);
51             }
52         }
53     }
54 }