Java RuntimeException equivalent in C#?

leeand00 picture leeand00 · Mar 23, 2011 · Viewed 19.9k times · Source

Does C# have the equivalent of Java's java.lang.RuntimeException?

(I.E. an exception that can be thrown without the necessity of being caught, or the program crashing when the exception is thrown.)

Answer

Hans Passant picture Hans Passant · Mar 23, 2011

SystemException is the equivalent, it is the base class of all exceptions that can be raised by .NET code. As opposed to application exceptions.

From the comments it however sounds like you want to catch this exception. In which case you should never use SystemException, you'll catch too many. Make your own exception class, derived from Exception.

There are no exception specifications in .NET, in case that's what you're after.