2 * Copyright (c) 2020 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.
18 using Tizen.Internals.Errors;
20 namespace Tizen.Peripheral
23 /// The class that represents the exception which will be thrown when the application can not control the peripherial.
25 internal static class ExceptionFactory
27 internal static Exception CreateException(ErrorCode errorCode)
29 Log.Error("Peripheral", $"Error {errorCode}");
33 case ErrorCode.IoError:
34 return new InvalidOperationException("I/O Error occured");
36 case ErrorCode.NoSuchDevice:
37 return new InvalidOperationException("No such device");
39 case ErrorCode.TryAgain:
40 return new InvalidOperationException("Try again");
42 case ErrorCode.OutOfMemory:
43 return new Exception("Out of memory");
45 case ErrorCode.PermissionDenied:
46 return new UnauthorizedAccessException("Permission denied");
48 case ErrorCode.ResourceBusy:
49 return new InvalidOperationException("Resource is busy");
51 case ErrorCode.InvalidParameter:
52 return new ArgumentException("Invalid parameters provided");
54 case ErrorCode.NotSupported:
55 return new InvalidOperationException("I/O Error occured");
57 case ErrorCode.Unknown:
58 return new InvalidOperationException("Unknown exception");
61 return new Exception("");