.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Threading.Tasks;

class Program
  {
    static public void Main(string[] args)
    {
      try
      {
        Program.ThrowErrorInTask();
        Console.WriteLine("Exception not caught");
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex);
      }
    }
	static public void ThrowErrorInTask()
    {
      Task.Run(() =>
      {
        throw new Exception("Something happened");
      });
    }
  }
;