CoreCLR on Mac:体验managed exception handling
C#测试代码:
using System; class Program
{
static void A()
{
try
{
Console.WriteLine("Throwing an exception");
throw new Exception("Did you catch it?");
}
finally
{
Console.WriteLine("A.finally()");
}
} static void B()
{
try
{
C();
Console.WriteLine("Failure! Exception has not been thrown.");
}
catch (Exception ex)
{
Console.WriteLine("Test B: success! Caught exception!\n" + ex.ToString());
}
finally
{
Console.WriteLine("B.finally()");
}
} static void C()
{
A();
} static void D()
{
try
{
try
{
Console.WriteLine("Throwing an exception");
throw new Exception("Did you catch it in the right handler?");
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("Test D: Failed. Called wrong handler.\n" + e.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine("Test D: success! Caught exception!\n" + ex.ToString());
}
} static void Main()
{
Console.WriteLine("Testing A");
try
{
A();
Console.WriteLine("Failure! Exception has not been thrown.");
}
catch (Exception ex)
{
Console.WriteLine("Test A: success! Caught exception!\n" + ex.ToString());
}
finally
{
Console.WriteLine("Main.finally().");
} Console.WriteLine("\nTesting B"); B(); Console.WriteLine("\nTesting D"); D(); Console.WriteLine("\nTesting class TestE"); TestE.Run(); Console.WriteLine("Exiting test");
} class TestE
{
static void A()
{
try
{
Console.WriteLine("In A");
B();
}
catch (ArgumentException ae)
{
Console.WriteLine("Error! Caught ArgumentException.\n" + ae.ToString());
}
} static void B()
{
try
{
Console.WriteLine("In B");
C();
}
finally
{
Console.WriteLine("Leaving B");
}
} static void C()
{
Console.WriteLine("In C");
D();
Console.WriteLine("Error! A() should not be reached in C()");
A();
} static void D()
{
Console.WriteLine("In D, throwing...");
throw new Exception("Exception test");
} public static void Run()
{
try
{
A();
}
catch (Exception ex)
{
Console.WriteLine("Test C: success! Caught exception!\n" + ex.ToString());
}
}
}
}
Throw Exception
代码编译:
mcs -nostdlib -r:compile_r_lib/mscorlib.dll -r:compile_r_lib/System.Runtime.dll -r:compile_r_lib/System.Console.dll app/ThrowException.cs
代码运行:
runtime_mac/corerun app/ThrowException.exe
在没有实现managed exception handling时的运行结果:
Testing A
Throwing an exception
{0x7fff7c0e1300-0x108e7c840} ASSERT [DEBUG ] at
/git/dotnet/coreclr/src/pal/src/arch/i386/context.cpp.38:
Trace/BPT trap: 5
在初步实现managed exception handling后的运行结果:
Testing A
Throwing an exception
A.finally()
Test A: success! Caught exception!
System.Exception: Did you catch it?
at Program.A()
at Program.Main()
Main.finally(). Testing B
Throwing an exception
A.finally()
Test B: success! Caught exception!
System.Exception: Did you catch it?
at Program.A()
at Program.B()
B.finally() Testing D
Throwing an exception
Test D: success! Caught exception!
System.Exception: Did you catch it in the right handler?
at Program.D()
Trace/BPT trap: 5
对应的git提交:Implement basic support for managed exception handling
对应的github pull request:Implement basic support for managed exception handling
CoreCLR on Mac:体验managed exception handling的更多相关文章
- Exception Handling引入MVP
异常处理(Exception Handling)是所有系统的最基本的基础操作之一,其它的比如日志(Logging).审核(Auditing).缓存(Caching).事务处理(Transaction) ...
- Unity、Exception Handling引入MVP
什么是MVP?在“MVP初探”里就有讲过了,就是一种UI的架构模式. 简单的描述一下Unity和Exception Handling Application Block: Unity是一个轻量级的可扩 ...
- Exception Handling in ASP.NET Web API webapi异常处理
原文:http://www.asp.net/web-api/overview/error-handling/exception-handling This article describes erro ...
- Exception Handling Statements (C# Reference)
Exception Handling Statements (C# Reference) C# provides built-in support for handling anomalous sit ...
- Exception Handling in ASP.NET Web API
public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErr ...
- [转]java-Three Rules for Effective Exception Handling
主要讲java中处理异常的三个原则: 原文链接:https://today.java.net/pub/a/today/2003/12/04/exceptions.html Exceptions in ...
- How a C++ compiler implements exception handling
Introduction One of the revolutionary features of C++ over traditional languages is its support for ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block 使用企业库异常处理应用程序模块的 ...
- Akka(32): Http:High-Level-Api,Route exception handling
Akka-http routing DSL在Route运算中抛出的异常是由内向外浮出的:当内层Route未能捕获异常时,外一层Route会接着尝试捕捉,依次向外扩展.Akka-http提供了Excep ...
随机推荐
- sqoop1.99.6 update导出语句
我们采用sqoop-export插入数据的时候,如果主键已经存在了,插入会失败.想要根据主键判断是否要进行insert操作还是update操作,sqoop提供了update语法.示例 sqoop -- ...
- linux shell学习笔记
一 变量 声明变量: my_var='ddd'使用变量: ${my_var}设置为只读变量: readonly my_var删除变量: unset my_var 注意只读变量不能被删除 变量类型:( ...
- 众安「尊享e生」果真牛的不可一世么?
近日,具有互联网基因的.亏损大户(成立三年基本没盈利,今年二季度末亏损近4亿,你能指望它多厉害?).财产险公司—众安推出“尊享e生”中高端医疗保险(财险公司经营中高端医疗真的很厉害?真的是中高端医疗险 ...
- 27、初步探索echarts源码
1.首先发现随笔中凡是和echarts相关的点击率都特别高,于是乎就接着写了echarts因为感觉要转点击率 首先声明我并不是专业做前端的,所以如果有些说得不对的地方,希望前端大神们出来指正 首先发现 ...
- 使用history.back()出现"警告: 网页已过期的解决办法"
原因: 表单提交页面中使用了 session_start 函数.由于我们后退浏览的是缓存页,而该函数会强制当前页面不被缓存. 解决: PHP: 此提示出现在一个POST提交的页面,点到其它页面后,通过 ...
- 解决PHP在IE中下载文件,中文文件名乱码问题
if( stripos($_SERVER['HTTP_USER_AGENT'], 'MSIE')!==false ) $filename = urlencode( $filename ); // 输入 ...
- VC++中操作XML(MFC、SDK)转
[转]VC++中操作XML(MFC.SDK) XML在Win32程序方面应该没有在Web方面应用得多,很多Win32程序也只是用XML来存存配置信息而已,而且没有足够的好处的话还不如用ini.VC++ ...
- Spring MVC实例(增删改查)
数据库配置文件application-context-jdbc.xml <?xml version="1.0" encoding="UTF-8"?> ...
- sp_MSforeachtable使用方法
1)说明系统存储过程sp_MSforeachtable和sp_MSforeachdb,是微软提供的两个不公开的存储过程,从ms sql 6.5开始.存放在SQL Server的MASTER数据库中. ...
- codeforces 420B Online Meeting
一道实现很蛋疼的题.必须静下理清思路,整理出各种情况.不然就会痛苦地陷入一大堆if..else里不能自拔. #pragma comment(linker, "/STACK:102400000 ...