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 ...
随机推荐
- 关于yaha中文分词(将中文分词后,结合TfidfVectorizer变成向量)
https://github.com/jannson/yaha # -*- coding: utf-8 -*- """ Created on Wed Aug 10 08: ...
- 【转载】shell编程——if语句 if -z -n -f -eq -ne -lt
shell编程中条件表达式的使用 if 条件then Commandelse Commandfi 别忘了这个结尾 If语句忘了结尾fites ...
- 命令行启动win7系统操作部分功能
control.exe /name microsoft.folderoptions 启动资源管理器的 文件夹属性 选项卡 control.exe /name Microsoft.AddHardware ...
- Ruby-调用windows窗体
发现SharpDevelop 也支持Ruby ,特别是可以直接把winform的控件直接用在 require "mscorlib" require "System.Win ...
- Windows 窗体设计器中的设计时错误
当修改窗体里面某一项时导致窗体报错,但是编译运行没问题,报"依赖项问题"则只需要把报错的那个依赖项删除后再重新引用.
- 《机器学习实战》学习笔记——第2章 KNN
一. KNN原理: 1. 有监督的学习 根据已知事例及其类标,对新的实例按照离他最近的K的邻居中出现频率最高的类别进行分类.伪代码如下: 1)计算已知类别数据集中的点与当前点之间的距离 2)按照距离从 ...
- oracle数据学习第二天
今天主要加强了对oracle数据库的数据类型一些相关函数的学习 (一)char和varchar2 字符串函数 <1>concat(char1,char2)字符串连接函数,用于连接两个字 ...
- ios 更新约束
[view setNeedsUpdateConstraints]; [view updateConstraintsIfNeeded]; [view setNeedsLayout]; ...
- Oracle Database常用补丁集Patch号及各版本PSU
Oracle Database常用补丁集Patch号及各版本PSU------------------------------------------------------------------- ...
- React Developer Tools 安装小提示
1,在google市场里边,安装React Developer Tools之后,发现是开启的,但是按下F12后,并没有发现react选项 2,后来通过查资料,发现必须是运行react项目的时候,才出现 ...