Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.StreamRecorder / StreamRecorder / StreamRecorderErrorFactory.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     internal enum StreamRecorderError
23     {
24         None = ErrorCode.None,
25         InvalidParameter = ErrorCode.InvalidParameter,
26         TizenErrorStreamRecorder = -0x01A10000,
27         InvalidState = TizenErrorStreamRecorder | 0x01,
28         OutOfMemory = ErrorCode.OutOfMemory,
29         InvalidOperation = ErrorCode.InvalidOperation,
30         OutOfStorage = TizenErrorStreamRecorder | 0x02,
31         PermissionDenied = ErrorCode.PermissionDenied,
32         NotSupported = ErrorCode.NotSupported,
33     }
34
35     internal static class StreamRecorderErrorFactory
36     {
37         internal static void ThrowException(int errorCode, string errorMessage = null, string paramName = null)
38         {
39             StreamRecorderError err = (StreamRecorderError)errorCode;
40             if(string.IsNullOrEmpty(errorMessage)) {
41                 errorMessage = err.ToString();
42             }
43             switch((StreamRecorderError)errorCode) {
44             case StreamRecorderError.InvalidParameter:
45                 throw new ArgumentException(errorMessage, paramName);
46             case StreamRecorderError.OutOfMemory:
47                 throw new OutOfMemoryException(errorMessage);
48             case StreamRecorderError.PermissionDenied:
49                 throw new UnauthorizedAccessException(errorMessage);
50             case StreamRecorderError.NotSupported:
51                 throw new NotSupportedException(errorMessage);
52             case StreamRecorderError.InvalidState:
53             case StreamRecorderError.InvalidOperation:
54             case StreamRecorderError.OutOfStorage:
55                 throw new InvalidOperationException(errorMessage);
56             }
57         }
58     }
59 }
60