/// <summary> /// Utility method to check for error, returns false if failed and print warning messages /// </summary> /// <returns>true in case of no error, false otherwise</returns> internal static bool WarnIfFailed(this Interop.ErrorCode err, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) { if (err.IsFailed()) { Log.Info(LogTag, $"{msg}, err: {err.ToString()}", file, func, line); Console.WriteLine($"I/{LogTag}: {msg}, err: {err.ToString()}"); return(false); } return(true); }
/// <summary> /// Utility method to check for error, returns false if failed and throw exception /// </summary> /// <returns>true in case of no error</returns> internal static bool ThrowIfFailed(this Interop.ErrorCode err, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0) { if (err.IsFailed()) { Log.Error(LogTag, $"{msg}, err: {err.ToString()}", file, func, line); Console.WriteLine($"E/{LogTag}: {msg}, err: {err.ToString()}"); throw err.GetException(msg); } return(true); }
internal static Exception GetException(this Interop.ErrorCode err, string message) { string errMessage = $"{message}, err: {err.ToString()}"; switch (err) { //case ErrorCode.None: case Interop.ErrorCode.PermissionDenied: return(new System.UnauthorizedAccessException(errMessage)); case Interop.ErrorCode.InvalidParameter: return(new System.ArgumentException(errMessage)); case Interop.ErrorCode.OutOfMemory: case Interop.ErrorCode.NotSupported: case Interop.ErrorCode.ConnectionTimeOut: case Interop.ErrorCode.NetworkUnreachable: case Interop.ErrorCode.InvalidOperation: case Interop.ErrorCode.KeyNotAvailable: case Interop.ErrorCode.ResourceBusy: case Interop.ErrorCode.Canceled: case Interop.ErrorCode.Unknown: case Interop.ErrorCode.ServiceNotAvailable: case Interop.ErrorCode.NotFound: default: return(new System.InvalidOperationException(errMessage)); } }
internal static Exception GetException(this Interop.ErrorCode err, string message) { string errMessage = $"{message}, err: {err.ToString()}"; switch (err) { //case Interop.ErrorCode.None: case Interop.ErrorCode.PermissionDenied: return(new UnauthorizedAccessException(errMessage)); case Interop.ErrorCode.InvalidParameter: return(new ArgumentException(errMessage)); case Interop.ErrorCode.TimedOut: return(new TimeoutException(errMessage)); case Interop.ErrorCode.OutOfMemory: return(new OutOfMemoryException(errMessage)); case Interop.ErrorCode.NotSupported: return(new NotSupportedException(errMessage)); case Interop.ErrorCode.IoError: case Interop.ErrorCode.NoSuchDevice: case Interop.ErrorCode.ResourceBusy: case Interop.ErrorCode.BrokenPipe: case Interop.ErrorCode.InterruptedSysCall: case Interop.ErrorCode.Unknown: case Interop.ErrorCode.NotFound: case Interop.ErrorCode.Overflow: case Interop.ErrorCode.DeviceNotOpened: default: return(new InvalidOperationException(errMessage)); } }