using System;
using System.IO;
using System.Security.Permissions;
// Security permission request.
[assembly:FileIOPermissionAttribute(SecurityAction.RequestMinimum, All = @"c:\data.txt")]
public class ProcessFile {
public static void Main() {
try {
StreamReader sr = File.OpenText("data.txt");
Console.WriteLine("The first line of this file is {0}", sr.ReadLine());
}
catch(Exception e) {
Console.WriteLine("An error occurred: '{0}'", e);
}
}
}
using System;
public class Employee
{
//Create employee level property.
public int Emlevel
{
get
{
return(emlevel);
}
set
{
emlevel = value;
}
}
int emlevel;
}
public class Ex13
{
public static void PromoteEmployee(Object emp)
{
//Cast object to Employee.
Employee e = (Employee) emp;
// Increment employee level.
e.Emlevel = e.Emlevel + 1;
}
public static void Main()
{
try
{
Object o = new Employee();
DateTime newyears = new DateTime(2001, 1, 1);
//Promote the new employee.
PromoteEmployee(o);
//Promote DateTime; results in InvalidCastException as newyears is not an employee instance.
PromoteEmployee(newyears);
}
catch (InvalidCastException e)
{
Console.WriteLine("Error passing data to PromoteEmployee method. " + e);
}
}
}
using System;
using System.IO;
public class ProcessFile
{
public static void Main()
{
FileStream fs = null;
try
{
//Opens a text tile.
fs = new FileStream(@"C:\temp\data.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);
string line;
//A value is read from the file and output to the console.
line = sr.ReadLine();
Console.WriteLine(line);
}
catch(FileNotFoundException e)
{
Console.WriteLine("[Data File Missing] {0}", e);
throw new FileNotFoundException(@"data.txt not in c:\temp directory]",e);
}
finally
{
if (fs != null)
fs.Close();
}
}
}
using System;
class ArgumentOutOfRangeExample
{
static public void Main()
{
int[] array1={0,0};
int[] array2={0,0};
try
{
Array.Copy(array1,array2,-1);
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine("Error: {0}",e);
}
finally
{
Console.WriteLine("This statement is always executed.");
}
}
}
public class Doer
{
public static void ProcessMessage(string message)
{
if (message == null)
{
throw new ArgumentNullException("message");
}
}
}
Tester部分
public class Tester
{
public static void TesterDoer(ICollection<string> messages)
{
foreach (string message in messages)
{
if (message != null)
{
Doer.ProcessMessage(message);
}
}
}
}
public void Do()
{
string s = “a”;
double d;
try
{
d = Double.Parse(s);
}
catch (Exception ex)
{
d = 0;
}
}
public void TryDo()
{
string s = "a";
double d;
if (double.TryParse(s, out d) == false)
{
d = 0;
}
}
public class BusinessLayerException : ApplicationException
{
public BusinessLayerException() : base()
{
}
public BusinessLayerException(string message) : base(message)
{
}
public BusinessLayerException(string message, Exception exception) :
base(message, exception)
{
}
protected BusinessLayerException(SerializationInfo info, StreamingContext context) :
base(info, context)
{
}
}
<add name="Wrap Policy"> <exceptionTypes> <add type="System.Data.DBConcurrencyException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="ThrowNewException" name="DBConcurrencyException"> <exceptionHandlers> <add exceptionMessage="Wrapped Exception: A recoverable error occurred while attempting to access the database." exceptionMessageResourceType="" wrapExceptionType="ExceptionHandlingQuickStart.BusinessLayer.BusinessLayerException, ExceptionHandlingQuickStart.BusinessLayer" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Wrap Handler" /> </exceptionHandlers> </add> </exceptionTypes> </add>
public bool ProcessWithWrap()
{
try
{
this.ProcessB();
}
catch(Exception ex)
{
// Quick Start is configured so that the Wrap Policy will
// log the exception and then recommend a rethrow.
bool rethrow = ExceptionPolicy.HandleException(ex, "Wrap Policy");
if (rethrow)
{
throw;
}
}
return true;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有