C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,216 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
Please see the following photo from C# Book.
Isn't it better to write FormatException first and then SystemException? because Format Exception is a more specific class than System Exception.
If Format Exception occurs, the first catch section (System Exception) will handle it because a Format Exception is a type of System Exception. and never Format exception will execute when Format Exception occurs.
Not only is it better - it's mandatory. The compiler will give you an error if you're catching a less-derived Exception before a more-derived Exception: