本文整理汇总了C#中System.IO.IOException类的典型用法代码示例。如果您正苦于以下问题:C# IOException类的具体用法?C# IOException怎么用?C# IOException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IOException类属于System.IO命名空间,在下文中一共展示了IOException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostEditorStorageException
private PostEditorStorageException(IOException ex)
: base(StringId.PostEditorStorageExceptionTitle2,
StringId.PostEditorStorageExceptionMessage2,
ex.GetType().Name,
ex.Message)
{
}
示例2: CustomMediaRetryPolicyTestExceededMaxRetryAttempts
public void CustomMediaRetryPolicyTestExceededMaxRetryAttempts()
{
MediaRetryPolicy target = new TestMediaServicesClassFactoryForCustomRetryPolicy(null).GetBlobStorageClientRetryPolicy();
int exceptionCount = 4;
int expected = 10;
//This is the new exception included for retrypolicy in the customretrypolicy
var fakeException = new IOException("CustomRetryPolicyException");
Func<int> func = () =>
{
if (--exceptionCount > 0) throw fakeException;
return expected;
};
try
{
target.ExecuteAction(func);
}
catch (AggregateException ax)
{
IOException x = (IOException)ax.Flatten().InnerException;
Assert.AreEqual(1, exceptionCount);
Assert.AreEqual(fakeException, x);
//Exception is retried only for max retrial attempts,
//In this case there are max of 2 attempts for blob retry policy.
Assert.AreEqual(exceptionCount, 1);
throw;
}
}
示例3: AsyncRead
private void AsyncRead (Handle handle, Result result, byte[] buf,
ulong bytesRequested, ulong bytesRead)
{
if (result == Result.Ok) {
Array.Copy (buf, 0, buffer, offset + count - bytesRemaining, (int)bytesRead);
bytesRemaining -= (int)bytesRead;
if (bytesRemaining > 0) {
buf = new byte[bytesRemaining];
Async.Read (handle, out buf[0], (uint)bytesRemaining,
new AsyncReadCallback (AsyncRead));
} else if (cback != null) {
asyncResult.SetComplete (null, count);
cback (asyncResult);
}
} else if (result == Result.ErrorEof) {
Array.Copy (buf, 0, buffer, offset + count - bytesRemaining, (int)bytesRead);
bytesRemaining -= (int)bytesRead;
asyncResult.SetComplete (null, count - bytesRemaining);
if (cback != null)
cback (asyncResult);
} else if (cback != null) {
Exception e = new IOException (Vfs.ResultToString (result));
asyncResult.SetComplete (e, -1);
cback (asyncResult);
}
}
示例4: AddFileInUseTests
public void AddFileInUseTests()
{
// Arrange
var fileName = @"x:\test\temp.txt";
var exception = new IOException("file in use");
var stream = new MemoryStream();
var zip = new ZipArchive(stream, ZipArchiveMode.Create);
var tracer = new Mock<ITracer>();
var file = new Mock<FileInfoBase>();
// setup
file.Setup(f => f.OpenRead())
.Throws(exception);
file.SetupGet(f => f.FullName)
.Returns(fileName);
tracer.Setup(t => t.Trace(It.IsAny<string>(), It.IsAny<IDictionary<string, string>>()))
.Callback((string message, IDictionary<string, string> attributes) =>
{
Assert.Contains("error", attributes["type"]);
Assert.Contains(fileName, attributes["text"]);
Assert.Contains("file in use", attributes["text"]);
});
// Act
zip.AddFile(file.Object, tracer.Object, String.Empty);
zip.Dispose();
// Assert
tracer.Verify(t => t.Trace(It.IsAny<string>(), It.IsAny<IDictionary<string, string>>()), Times.Once());
zip = new ZipArchive(ReOpen(stream));
Assert.Equal(0, zip.Entries.Count);
}
示例5: ShowScanningError
public static void ShowScanningError(IOException exception)
{
var message = exception.Message;
var options = MessageBoxButton.OK;
var icon = MessageBoxImage.Error;
ShowMessageBox(message, options, icon);
}
示例6: IsSharingViolation
static bool IsSharingViolation(IOException ex)
{
// http://stackoverflow.com/questions/425956/how-do-i-determine-if-an-ioexception-is-thrown-because-of-a-sharing-violation
// don't ask...
var hResult = System.Runtime.InteropServices.Marshal.GetHRForException(ex);
const int sharingViolation = 32;
return (hResult & 0xFFFF) == sharingViolation;
}
示例7: SetLength
public override void SetLength(long value)
{
if (BreakHow == BreakHowType.ThrowOnSetLength)
{
ThrownException = new IOException();
throw ThrownException;
}
}
示例8: CannotFetchDataException
/// <summary>The default constructor for CannotFetchDataException.</summary>
/// <remarks>The default constructor for CannotFetchDataException.</remarks>
/// <param name="ex"></param>
public CannotFetchDataException(IOException ex, string serviceName)
: this(ex is
UnknownHostException ? CannotFetchDataException.MSG.UNKNOWN_HOST_EXCEPTION : CannotFetchDataException.MSG
.IO_EXCEPTION, serviceName)
{
cause = ex;
this.serviceName = serviceName;
}
示例9: T202_FileFormatException
public void T202_FileFormatException()
{
var e2 = new IOException("Test");
var e = new FileFormatException("Test", e2);
Assert.Equal("Test", e.Message);
Assert.Null(e.SourceUri);
Assert.Same(e2, e.InnerException);
}
示例10: error
public IOException error(Exception why)
{
if (why == null)
throw new ArgumentNullException ("why");
IOException e;
e = new IOException("Encryption error: " + why.Message, why);
return e;
}
示例11: TestLogExceptionPrepends
public void TestLogExceptionPrepends()
{
var exception = new IOException("io");
_logger.LogException(exception, "Foo {0}", "Bar");
var result = _writer.ToString();
Assert.That(result, Is.StringStarting("Exception: IOException, io\r\n"));
}
示例12: TestLogExceptionAppendsArgs
public void TestLogExceptionAppendsArgs()
{
var exception = new IOException("io");
_logger.LogException(exception, "Foo {0}", "Bar");
var result = _writer.ToString();
Assert.That(result, Is.StringEnding("Foo Bar\r\n"));
}
示例13: ClusterBase
static ClusterBase()
{
var allDead = new IOException("All nodes are dead.");
// cached tasks for error reporting
failSingle = new TaskCompletionSource<IOperation>();
failBroadcast = new TaskCompletionSource<IOperation[]>();
failSingle.SetException(allDead);
failBroadcast.SetException(allDead);
}
示例14: GetErrorCode
internal static int GetErrorCode(IOException ioe)
{
#if !WindowsCE && !SILVERLIGHT && !NETFX_CORE
var permission = new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode);
permission.Demand();
return Marshal.GetHRForException(ioe) & 0xFFFF;
#else
return 0;
#endif
}
示例15: TryWrapException
// Convert HttpListenerExceptions to IOExceptions
protected override bool TryWrapException(Exception ex, out Exception wrapped)
{
if (ex is HttpListenerException)
{
wrapped = new IOException(string.Empty, ex);
return true;
}
wrapped = null;
return false;
}