Skip to content

Exception handling

CodingUnit edited this page Dec 9, 2011 · 3 revisions

Exception handling

  • Category: Exceptions
  • Description: Raising an 'ArgumentException' exception, and filtering for .NET exceptions
  • Code:
using Nemerle;
using System;
using System.Console;
using System.IO;

try 
{
    WriteLine("About to raise an ArgumentException exception...");
    if (DateTime.Now.DayOfWeek == DayOfWeek.Tuesday)
        throw System.ArgumentException("Not today, it's Tuesday")
    else 
        throw System.ApplicationException("Hey, it's not Tuesday...")
}
catch
{
    | e is System.ArgumentException    => WriteLine($"Caught an ArgumentException, e.Message = $e")
    | e is System.ApplicationException => WriteLine($"Caught an ApplicationException, e.Message = $e")
    | _                                => WriteLine("Some other exception was caught")
}
  • Execution Result (in case of Tuesday):
About to raise an ArgumentException exception...
Caught an ArgumentException, e.Message = Not today, it's Tuesday
  • Execution Result (in other cases):
About to raise an ArgumentException exception...
Caught an ApplicationException, e.Message = Hey, it's not Tuesday...

[Copyright ©](Terms of use, legal notice)

Clone this wiki locally