Throw Exception from a function : Exception Throw « Language Basics « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / CSharp Tutorial » Language Basics » Exception Throw 
1. 21. 3. Throw Exception from a function
 


using System;

class MainClass
{
    
    static void AFunction()
    {
        int Zero = 0;
        int j = 22 / Zero;
    }
    public static void Main()
    {
        try
        {
            Console.WriteLine("efore Function");
            AFunction();
        }
        catch (DivideByZeroException e)
        {
            Console.WriteLine("DivideByZero {0}", e);
        }
    }
}

        
efore Function
DivideByZero System.DivideByZeroException: Attempted to divide by zero.
   at MainClass.Main()
  
1. 21. Exception Throw
1. 21. 1. Manually throw an exception.
1. 21. 2. Rethrow an exception
1. 21. 3. Throw Exception from a function
1. 21. 4. Wrap exception in another one, adding additional context
1. 21. 5. Throw Exception in finally statement
1. 21. 6. Creating and throwing an exception object
ww__w_._ja___va___2s__.__co___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.