Esempio n. 1
0
 /*
  *  You shouldn’t throw exceptions when dealing with expected situations.
  *
  *  Exception handling changes the normal expected flow of your program.
  *  This makes it harder to read and maintain code that uses exceptions,
  *  especially when they are used in normal situations.
  *
  *  Using exceptions also incurs a slight performance hit.
  *  Because the runtime has to search all outer catch blocks until it finds a matching block,
  *  and when it doesn’t, has to look if a debugger is attached, it takes slightly more time to handle.
  *  When a real unexpected situation occurs that will terminate the application, this won’t be a problem.
  *  But for regular program flow, it should be avoided.
  *  Instead you should have proper validation and not rely solely on exceptions.
  *
  *  ■ In the .NET Framework, you should use exceptions to report errors instead of error codes.
  *  ■■ Exceptions are objects that contain data about the reason for the exception.
  *  ■■ You can use a try block with one or more catch blocks to handle different types of exceptions.
  *  ■■ You can use a finally block to specify code that should always run after, whether or not an exception occurred.
  *  ■■ You can use the throw keyword to raise an exception.
  *  ■■ You can define your own custom exceptions when you are sure that users of your code will handle it in a different way.
  *  Otherwise, you should use the standard .NET Framework exceptions.
  *
  */
 static void Main(string[] args)
 {
     //ExceptionFinalize a = new ExceptionFinalize();
     ExceptionFinalize.Example();
 }
Esempio n. 2
0
 public static void Example()
 {
     ExceptionFinalize.Example();
 }