【发布时间】:2017-11-12 12:14:28
【问题描述】:
我有一个小型控制台应用程序,它将安排在一天中的不同时间间隔,这个控制台应用程序将从 ftp 下载文件。 我有一个名为 BatchProcessor 的类,它从 ftp 下载文件,根据供应商类型将它们解压缩到不同的供应商文件夹中,然后读取并存储到 SQL Server 数据库中。
我需要一些关于我所做的是对还是错的建议,因为我几乎需要在任何阶段捕获异常......
这是代码骨架。 Program.cs
class Program
{
static void Main(string[] args)
{
var batchProcessor = new BatchProcessor();
batchProcessor.Start();
}
}
这是 BatchProcessor 类
public class BatchProcessor
{
public bool Start()
{
try
{
var result = Connect();
if (!result) return false;
result = SearchLatestFiles();
if (!result) return false;
result = DownloadFiles();
if (!result) return false;
}
catch (Exception)
{
throw;
}
}
public bool Connect()
{
try
{
// 1. Connect to FTP
}
catch (Exception)
{
throw;
}
}
public bool SearchLatestFiles()
{
try
{
// 1. Look for the latest fils
}
catch (Exception)
{
throw;
}
}
public bool DownloadFiles()
{
try
{
// 1. Latest files found so download them.
}
catch (Exception)
{
throw;
}
}
}
【问题讨论】:
标签: .net c#-4.0 exception-handling