CoreCLR on Mac: Experience managed exception handling

Source: Internet
Author: User
Tags throw exception

C # test Code:

usingSystem;classprogram{Static voidA () {Try{Console.WriteLine ("throwing an exception"); Throw NewException ("did you catch it?"); }        finally{Console.WriteLine ("a.finally ()"); }    }    Static voidB () {Try{C (); Console.WriteLine ("failure! Exception have not been thrown."); }        Catch(Exception ex) {Console.WriteLine ("Test b:success! Caught exception!\n"+Ex.        ToString ()); }        finally{Console.WriteLine ("b.finally ()"); }    }    Static voidC () {A (); }    Static voidD () {Try        {            Try{Console.WriteLine ("throwing an exception"); Throw NewException ("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 voidMain () {Console.WriteLine ("Testing A"); Try{A (); Console.WriteLine ("failure! Exception have 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"); }    classTeste {Static voidA () {Try{Console.WriteLine ("In A");            B (); }            Catch(ArgumentException ae) {Console.WriteLine ("error! Caught argumentexception.\n"+AE.            ToString ()); }        }        Static voidB () {Try{Console.WriteLine ("In B");            C (); }            finally{Console.WriteLine ("Leaving B"); }        }        Static voidC () {Console.WriteLine ("In C");            D (); Console.WriteLine ("error! A () should not being reached in C ()");        A (); }        Static voidD () {Console.WriteLine ("in D, throwing ..."); Throw NewException ("Exception Test"); }         Public Static voidRun () {Try{A (); }            Catch(Exception ex) {Console.WriteLine ("Test c:success! Caught exception!\n"+Ex.            ToString ()); }        }    }}
Throw Exception

Code compilation:

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

Code to run:

Runtime_mac/corerun App/throwexception.exe

Running results when managed exception handling is not implemented:

Testing athrowing an exception{0x7fff7c0e1300-0x108e7c840} ASSERT [DEBUG  ] at/git/dotnet/coreclr/src/pal/src/ ARCH/I386/CONTEXT.CPP.38:TRACE/BPT Trap:5

The results of the operation after the initial implementation of managed exception handling:

Testing athrowing an exceptiona.finally () Test a:success! Caught exception! System.Exception:Did you catch it?   At PROGRAM.A () at   Program.main () main.finally (). Testing bthrowing an exceptiona.finally () Test b:success! Caught exception! System.Exception:Did you catch it?   At PROGRAM.A () @   program.b () b.finally () testing dthrowing an exceptiontest d:success! Caught exception! System.Exception:Did you catch it on the right handler?   At PROGRAM.D () trace/bpt Trap:5

corresponding git commit: Implement basic support for managed exception handling

The corresponding Git pull request:implement basic support for managed exception handling

CoreCLR on Mac: Experience managed exception handling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.