2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 using Tizen.Internals.Errors;
22 namespace Tizen.Network.IoTConnectivity
24 internal enum IoTConnectivityError
26 None = ErrorCode.None,
27 InvalidParameter = ErrorCode.InvalidParameter,
28 OutOfMemory = ErrorCode.OutOfMemory,
29 Io = ErrorCode.IoError,
30 PermissionDenied = ErrorCode.PermissionDenied,
31 NotSupported = ErrorCode.NotSupported,
32 NoData = ErrorCode.NoData,
33 TimedOut = ErrorCode.TimedOut,
34 Iotivity = -0x01C80000 | 0x01,
35 Representation = -0x01C80000 | 0x02,
36 InvalidType = -0x01C80000 | 0x03,
37 Already = -0x01C80000 | 0x04,
38 System = -0x01C80000 | 0x06,
41 internal static class IoTConnectivityErrorFactory
43 internal const string LogTag = "Tizen.Network.IoTConnectivity";
45 internal static void ThrowException(int err)
47 throw GetException(err);
50 internal static Exception GetException(int err)
52 IoTConnectivityError error = (IoTConnectivityError)err;
53 if (error == IoTConnectivityError.OutOfMemory)
55 return new OutOfMemoryException("Out of memory");
57 else if (error == IoTConnectivityError.InvalidParameter)
59 return new ArgumentException("Invalid parameter");
61 else if (error == IoTConnectivityError.Io)
63 return new IOException("I/O Error");
65 else if (error == IoTConnectivityError.NoData)
67 return new InvalidOperationException("No data found");
69 else if (error == IoTConnectivityError.TimedOut)
71 return new TimeoutException("timed out");
73 else if (error == IoTConnectivityError.PermissionDenied)
75 return new UnauthorizedAccessException("Permission denied");
77 else if (error == IoTConnectivityError.NotSupported)
79 return new NotSupportedException("Not supported");
81 else if (error == IoTConnectivityError.Representation)
83 return new InvalidOperationException("Representation error");
85 else if (error == IoTConnectivityError.InvalidType)
87 return new ArgumentException("Invalid type");
89 else if (error == IoTConnectivityError.Already)
91 return new InvalidOperationException("Duplicate");
93 else if (error == IoTConnectivityError.System)
95 return new InvalidOperationException("System error");
99 return new InvalidOperationException("Invalid operation");