Release 4.0.0-preview1-00175
[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             {
42                 errorMessage = err.ToString();
43             }
44             switch ((StreamRecorderError)errorCode)
45             {
46                 case StreamRecorderError.InvalidParameter:
47                     throw new ArgumentException(errorMessage, paramName);
48                 case StreamRecorderError.OutOfMemory:
49                     throw new OutOfMemoryException(errorMessage);
50                 case StreamRecorderError.PermissionDenied:
51                     throw new UnauthorizedAccessException(errorMessage);
52                 case StreamRecorderError.NotSupported:
53                     throw new NotSupportedException(errorMessage);
54                 case StreamRecorderError.InvalidState:
55                 case StreamRecorderError.InvalidOperation:
56                 case StreamRecorderError.OutOfStorage:
57                     throw new InvalidOperationException(errorMessage);
58             }
59         }
60     }
61 }
62