Unhandled exception is an exception which have not been handled in user code by a try/catch block.
There are a few exceptions which cannot be caught by a try/catch block in user code. For example: starting with the .NET Framework 2.0, you can't catch a StackOverflowException with a try/catch block.
You can reproduce it easily by having a function calling itself (which really may happen in a recursive function with no proper ending condition). For example:
using System;
namespace temp
{
class Program
{
static void Main(string[] args)
{
Main(args); // Oops, this recursion won't stop.
}
}
}
You can learn more about the example in Debug StackOverflow errors.
For the exceptions which are not being handled by try/catch in your code, depending to the framework which you are using, you can use the following options:
- Application.ThreadException and AppDomain.CurrentDomain.UnhandledException in desktop applications. (more example here)
- ASP.NET Error Handling
- Handle errors in ASP.NET Core
If you don't follow any of above mechanism, then you may need to look into Event Viewer to see the unhandled exceptions under Application event, for .NET Runtime or for your application.
Before you end with an unhandled exception, you may want to take a look at Best practices for exceptions which describes best practices for handling and throwing exceptions.