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的更多相关文章

  1. Exception Handling引入MVP

    异常处理(Exception Handling)是所有系统的最基本的基础操作之一,其它的比如日志(Logging).审核(Auditing).缓存(Caching).事务处理(Transaction) ...

  2. Unity、Exception Handling引入MVP

    什么是MVP?在“MVP初探”里就有讲过了,就是一种UI的架构模式. 简单的描述一下Unity和Exception Handling Application Block: Unity是一个轻量级的可扩 ...

  3. Exception Handling in ASP.NET Web API webapi异常处理

    原文:http://www.asp.net/web-api/overview/error-handling/exception-handling This article describes erro ...

  4. Exception Handling Statements (C# Reference)

    Exception Handling Statements (C# Reference) C# provides built-in support for handling anomalous sit ...

  5. Exception Handling in ASP.NET Web API

    public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErr ...

  6. [转]java-Three Rules for Effective Exception Handling

    主要讲java中处理异常的三个原则: 原文链接:https://today.java.net/pub/a/today/2003/12/04/exceptions.html Exceptions in ...

  7. How a C++ compiler implements exception handling

    Introduction One of the revolutionary features of C++ over traditional languages is its support for ...

  8. 黄聪:Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block 使用企业库异常处理应用程序模块的 ...

  9. Akka(32): Http:High-Level-Api,Route exception handling

    Akka-http routing DSL在Route运算中抛出的异常是由内向外浮出的:当内层Route未能捕获异常时,外一层Route会接着尝试捕捉,依次向外扩展.Akka-http提供了Excep ...

随机推荐

  1. objective c, category 和 protocol 中添加property

    property的本质是实例变量 + getter 和 setter 方法 category和protocol可以添加方法 category 和 protocol中可以添加@property 关键字 ...

  2. JS中的for/in语句和arguments参数

    在js应用中,有时候我们会遇到希望定义一个函数可以被不同情况调用,比如参数个数不固定的情况. 可以使用for/in语句和arguments参数解决. 举个简单例子:定义一个计算总和的函数,需要计算的数 ...

  3. CodeForces 689C Mike and Chocolate Thieves (二分)

    原题: Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the l ...

  4. Dobbo的继任者?试用微博RPC框架Motan

    从14年开始就陆续看到新浪微博RPC框架Motan的介绍,时隔两年后,微博团队终于宣布开源轻量级RPC框架Motan,项目地址: https://github.com/weibocom/motan/ ...

  5. NOI 2001 食物链(eat)

    1074 食物链 2001年NOI全国竞赛  时间限制: 3 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description ...

  6. ArcGIS Wpf MarkerSymbol 图形符号无法序列化为 JSON

    [问题贴,尚不知如何解决] 在GraphicsLayer中添加一个点,使用自定义模板渲染该点,在Vs2012设计界面可以看到,但运行时出现异常 代码如下: <esri:Graphic x:Nam ...

  7. (十一) 一起学 Unix 环境高级编程 (APUE) 之 高级 IO

    . . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编 ...

  8. iOS开发-xcdatamodeld文件 CoreData的介绍和使用,sqlite的使用

    CoreData的介绍和使用  源引:http://www.jianshu.com/p/d027090af00e CoreData是数据存储的一种方式,CoreData实质也是对SQLite的封装. ...

  9. CMS为什么采用“标记-清除”算法

    分代式GC里,年老代常用mark-sweep:或者是mark-sweep/mark-compact的混合方式,一般情况下用mark-sweep,统计估算碎片量达到一定程度时用mark-compact. ...

  10. android studio 代理配置

    android studio 代理设置,只支持http代理,不能用ss服务 中间加一层http转换 1远端ss 2client ss 端口 A 3client privoxy服服 代理ss A端口 到 ...