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. shopnc 二次开发 每日签到积分领取

    /* 开始shopnc!!!!! url:xxx.com/index.php?act=index&op=userjf 一个四线城市的半吊子程序员~ 实现:前台模板文件 随便加入<a> ...

  2. git push throws error: RPC failed; result=22, HTTP code = 411的解决办法

    原因:默认 Git 设置 http post 的缓存为 1MB,将其设置为 500MB 解决办法如下: git config http.postBuffer 524288000

  3. 双机相关知识(原理、LVM、Raid技术)

    1        双机知识 1.1         预备知识 1.1.1     基本概念 双机热备:双机热备双机管理软件可以根据心跳自动检测环境运行情况,如果发现一个节点挂掉了,会自动切换到另外一个 ...

  4. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  5. LVS集群类型

    一.LVS-NAT 简述:多目标的DNAT,通过Director修改请求报文中的目标地址和端口为LVS挑选出来的某RS的RIP和PORT实现转发 特点: (1)RIP和DIP必须在同一网络,且应该使用 ...

  6. python中的system函数与编码

    在调用os.system执行命令时,发现system不能接受unicode的命令.那么命令中却又包含以unicode表示的中文等字符怎么办? ——方法就是将unicode转化为utf8 path = ...

  7. Selenium2+python自动化3-解决pip使用异常

    一.pip出现异常 有一小部分童鞋在打开cmd输入pip后出现下面情况:Did not provide a commandDid not provide a command?这是什么鬼?正常情况应该是 ...

  8. java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView

    最近在学习drawerLayout时,遇到这个bug.如下示: java.lang.ClassCastException: android.widget.RelativeLayout cannot b ...

  9. Servlet实现定时刷新到另外一个页面response.setHeader("refresh", "3;url=/...")

    想要实现,访问Responsedemo11的时候,3秒钟后,跳转到ResponseDemo10 用   response.setHeader("refresh", "3; ...

  10. 利用fiddler模拟发送json数据的post请求

    fiddler是调试利器,有许多好用的功能,这里简单的介绍一下利用fiddler模拟发送post请求的例子 先简单介绍一下失败的例子,最后给出正确的方法