ASP.NET常见异常处理示例
- 将指定的年月日转初始化为DateTime新的实例(Nop.Admin.Controllers.OrderController.ParseProductAttributes)
case AttributeControlType.Datepicker:
{
var day = form[controlId + "_day"];
var month = form[controlId + "_month"];
var year = form[controlId + "_year"];
DateTime? selectedDate = null;
try
{
selectedDate = new DateTime(Int32.Parse(year), Int32.Parse(month), Int32.Parse(day));
}
catch { }
if (selectedDate.HasValue)
{
attributesXml = _productAttributeParser.AddProductAttribute(attributesXml,
attribute, selectedDate.Value.ToString("D"));
}
}
break; - 能否出订单信息(\src\Presentation\Nop.Web\Administration\Controllers\OrderController.cs(1346))
try
{
byte[] bytes = _exportManager.ExportOrdersToXlsx(orders);
return File(bytes, MimeTypes.TextXlsx, "orders.xlsx");
}
catch (Exception exc)
{
ErrorNotification(exc);
return RedirectToAction("List");
}
- 发送HTTP请求(\src\Plugins\Nop.Plugin.ExchangeRate.EcbExchange\EcbExchangeRateProvider.cs(60))
//get exchange rates to euro from European Central Bank
var request = (HttpWebRequest)WebRequest.Create("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
try
{
using (var response = request.GetResponse())
{
//load XML document
var document = new XmlDocument();
document.Load(response.GetResponseStream()); //add namespaces
var namespaces = new XmlNamespaceManager(document.NameTable);
namespaces.AddNamespace("ns", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref");
namespaces.AddNamespace("gesmes", "http://www.gesmes.org/xml/2002-08-01"); //get daily rates
var dailyRates = document.SelectSingleNode("gesmes:Envelope/ns:Cube/ns:Cube", namespaces);
DateTime updateDate;
if (!DateTime.TryParseExact(dailyRates.Attributes["time"].Value, "yyyy-MM-dd", null, DateTimeStyles.None, out updateDate))
updateDate = DateTime.UtcNow; foreach (XmlNode currency in dailyRates.ChildNodes)
{
//get rate
decimal currencyRate;
if (!decimal.TryParse(currency.Attributes["rate"].Value, out currencyRate))
continue; ratesToEuro.Add(new Core.Domain.Directory.ExchangeRate()
{
CurrencyCode = currency.Attributes["currency"].Value,
Rate = currencyRate,
UpdatedOn = updateDate
});
}
}
}
catch (WebException ex)
{
_logger.Error("ECB exchange rate provider", ex);
} - EF操作(\src\Libraries\Nop.Data\EfRepository.cs(182))
try
{
if (entities == null)
throw new ArgumentNullException("entities"); foreach (var entity in entities)
this.Entities.Remove(entity); this._context.SaveChanges();
}
catch (DbEntityValidationException dbEx)
{
throw new Exception(GetFullErrorText(dbEx), dbEx);
} - \src\Libraries\Nop.Core\WebHelper.cs(46)
protected virtual Boolean IsRequestAvailable(HttpContextBase httpContext)
{
if (httpContext == null)
return false; try
{
if (httpContext.Request == null)
return false;
}
catch (HttpException)
{
return false;
} return true;
} - \src\Libraries\Nop.Core\Plugins\PluginManager.cs(434)
try
{
File.Copy(plug.FullName, shadowCopiedPlug.FullName, true);
}
catch (IOException)
{
Debug.WriteLine(shadowCopiedPlug.FullName + " is locked, attempting to rename");
//this occurs when the files are locked,
//for some reason devenv locks plugin files some times and for another crazy reason you are allowed to rename them
//which releases the lock, so that it what we are doing here, once it's renamed, we can re-shadow copy
try
{
var oldFile = shadowCopiedPlug.FullName + Guid.NewGuid().ToString("N") + ".old";
File.Move(shadowCopiedPlug.FullName, oldFile);
}
catch (IOException exc)
{
throw new IOException(shadowCopiedPlug.FullName + " rename failed, cannot initialize plugin", exc);
}
//ok, we've made it this far, now retry the shadow copy
File.Copy(plug.FullName, shadowCopiedPlug.FullName, true);
}
ASP.NET常见异常处理示例的更多相关文章
- ASP.NET Core 异常处理与日志记录
1. ASP.NET Core 异常处理与日志记录 1.1. 异常处理 1.1.1. 异常产生的原因及处理 1.1.2. ASP.NET Core中启动开发人员异常页面 1.2. 日志记录 1.2.1 ...
- Asp.Net Core异常处理整理
目前版本是Asp.Net Core v1.1,这个版本的感觉对Http请求中的错误处理方便不是很完善. 没有HttpException异常类,不能在任何的地方自由的抛出对应的异常状态. 一.默认的异常 ...
- [整理]ASP.NET 中异常处理
[整理]ASP.NET 中异常处理 1.直接通过重写Controller的OnException来处理异常 public class HomeController : Controller { pub ...
- ASP.NET中异常处理的注意事项
一.ASP.NET中需要引发异常的四类情况 1.如果运行代码后,造成内存泄漏.资源不可用或应用程序状态不可恢复,则引发异常.Console这个类中,有很多类似这样的代码: if ((value < ...
- ASP.NET MVC异常处理
ASP.NET MVC异常处理方案 如何保留异常前填写表单的数据 ASP.NET MVC中的统一化自定义异常处理 MVC过滤器详解 MVC过滤器使用案例:统一处理异常顺道精简代码 ASP.NET MV ...
- Java Socket常见异常处理 和 网络编程需要注意的问题
在java网络编程Socket通信中,通常会遇到以下异常情况: 第1个异常是 java.net.BindException:Address already in use: JVM_Bind. 该异常发 ...
- [转]Linux中find常见用法示例
Linux中find常见用法示例[转]·find path -option [ -print ] [ -exec -ok command ] {} \;find命令的参 ...
- EDI数据导入的注意事项&常见异常处理
EXCEL表格注意事项: • 编码是0开头的,格式必须是文本,否则前面请加字母: • 注意全角半角,中文标点英文标点: • 编号文字类开头和结尾不要有空格,姓名中间也不要 ...
- Linux下命令行cURL的10种常见用法示例
curl的命令行工具功能非常强大,这些数据交互的功能基本上都是通过URL方式进行的,下面这篇文章主要给大家分享了在Linux中命令行cURL的10种常见用法示例,通过示例代码介绍的非常详细,需要的朋友 ...
随机推荐
- Python数据预处理:机器学习、人工智能通用技术(1)
Python数据预处理:机器学习.人工智能通用技术 白宁超 2018年12月24日17:28:26 摘要:大数据技术与我们日常生活越来越紧密,要做大数据,首要解决数据问题.原始数据存在大量不完整.不 ...
- 洛谷P1048 采药
题目OJ地址 https://www.luogu.org/problemnew/show/P1048 https://vijos.org/p/1104 题目描述辰辰是个天资聪颖的孩子,他的梦想是成为世 ...
- Ubuntu 16.04 升级git
To update git on Ubuntu 12.04 just follow this line of commands: sudo apt-get install python-softwar ...
- 基于cefsharp的用户浏览器
技术:vc++2015 概述 用于需要制作一个浏览器 winfrom 中浏览器的插件有很多种 如:WebBrowser , Web.kit等 但用于比较稳定 功能齐全的还是cefsharp 详细 ...
- 干货!最全羽毛球技术动态分解gif图
羽毛球的技术千变万化,但是离不开最基本的击球方法.下面通过一组形象的动态图,给你展现羽毛球的基本动作.大家,务必要收藏起来,慢慢体会哦! 一.发球 二.前场技术 1.网前球 2.搓球 3.勾球 4.推 ...
- APP开发的基本流程
一个独立App开发人的自白:做APP就是一场赌局,你要会押注 下面我们就直接来看下APP从业者必知的整个APP开发标准流程. 一般的APP开发及上线流程 步骤如下: 首先,制作一款APP,必须要有相关 ...
- LRU原理和Redis实现——一个今日头条的面试题(转载)
很久前参加过今日头条的面试,遇到一个题,目前半部分是如何实现 LRU,后半部分是 Redis 中如何实现 LRU. 我的第一反应是操作系统课程里学过,应该是内存不够的场景下,淘汰旧内容的策略.LRU ...
- 谈谈tmpdir与innodb_tmpdir的区别和用处
[背景] innodb_tmpdir是在innodb online ddl中提到的一个参数:大致的意思是innodb在做online-ddl的时候会向临时目录写入“临时排序文件” 而这些文件的大小基本 ...
- yaf项目将500错误打印到页面上
一般在yaf项目调试的时候,如果代码有错误,页面只会响应500错误,但看不到哪里报了什么错误,通过开启yaf的一个配置可以将错误信息显示在页面上. 打开项目的index.php入口文件,在开头加入如下 ...
- rm -rf python 实现 v0.1
#coding=utf- import os def join(arr,join_falg): res = "" for a in arr: res += a+join_falg ...