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. Python自动化 【第六篇】:Python基础-面向对象

      目录: 面向过程VS面向对象 面向对象编程介绍 为什么要用面向对象进行开发 面向对象的特性:封装.继承.多态 面向过程 VS 面向对象 面向过程编程(Procedural Programming) ...

  2. python 格式化 json输出

    利用python格式化json 字符串输出. $ echo '{"json":"obj"}' | python -m json.tool 利用python -m ...

  3. 127.0.0.1和localhost完全相等吗?

    今天在使用ajax发请求的时候遇到如下问题: 以[Access-Control-Allow-Origin]为关键字搜索的结果进行改进,但没有效果. 返回仔细查看错误提示,发现ajax请求的url是lo ...

  4. VHDL 学习

    近期在接触 VHDL,首先要本好书,个人觉得 1)<VHDL for engineer>  VHDL 大学实用教程 (这个名字翻译的无语...) 2)估计verilog的作者的 bhask ...

  5. QuerySet转化为JSON

    import json data = json.dumps(list(my_table.objects.all().values())) return HttpResponse(data)

  6. JSON.parse()和JSON.stringify()(转载)

    parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...

  7. python学习之——计算文件行数

    # -*- coding: cp936 -*- #转载源于:http://blog.csdn.net/houyj1986/article/details/21196027 #计算文件行数 #1.文件比 ...

  8. git 常用技巧

    撤销修改 撤销本地修改 git reset --hard 或者 git checkout -- . 切换分支 切换到前一分支 git checkout - 切换到某个分支 git checkout & ...

  9. 统计学习方法 AdaBoost

    提升方法的基本思路 在概率近似正确(probably approximately correct,PAC)学习的框架中, 一个概念(一个类),如果存在一个多项式的学习算法能够学习它,并且正确率很高,那 ...

  10. 《Java程序设计》课程准备之问卷调查

    一.你对自己的未来有什么规划?做了哪些准备? 答:未来就是找个好工作,在保证自己与父母生活条件良好的基础上,进一步的提高精神上的需求.如:旅游度假,支持更多业余爱好等.准备就是:好好学习,好好运动,好 ...