Sunday, April 19, 2015

Try Catch Finally For Managed Errors and Exception

Finally :
C# Support Another Statement Known as finally statement that can be used to handle an exception that is not caught by any of the previous catch statement , finally block can be used to handle any exception generated within a try block . It may be be added immediately after the last catch block shown as follows :
try                                                                                                      
{
  ...........
  ...........
}
finally
{
............
 ............
}

another example :

try                                                                                                      
{
  ...........
  ...........
}
catch(.........)
{
  ...........
  ..........
}
catch(.........)
{
  ...........
  ..........
}
finally
{
 ............
 ............
}

When a finally block is defined , this is guaranteed to execute , regardless of whether or not in exception is thrown , As a result , we can use it to perform certain house - keeping operation such as closing files and releasing system resource . 

Saturday, April 18, 2015

Briefly Explain About Exception Handling

Exceptions. 
All human endeavor has risk. Much like actions in our external reality, a computer's processes can fail. Nothing is safe.
It is awful. 
An error can occur at almost any statement. Checking for all these errors becomes unbearably complex. Exception handling separates this logic. It simplifies control flow.
However:It is best used only when needed—with the Tester-Doer pattern we keep exceptions exceptional.
Exceptional:
Grey areas exist. Exceptions are a high-level concept. What is exceptional depends on a program.
In programs, 
we can throw exceptions with a throw statement. But an exception is often thrown automatically by the runtime. An instruction may cause an invalid state.

Here:We divide by zero. Sadly this results in a DivideByZeroException. This operation cannot be continued.
Try:We use the try and catch blocks to structure our error handling. This may lead to cleaner code.
Based on:

.NET 4.5

C# program that throws an exception

using System;

class Program
{
    static void Main()
    {
 try
 {
     int value = 1 / int.Parse("0");
     Console.WriteLine(value);
 }
 catch (Exception ex)
 {
     Console.WriteLine(ex.Message);
 }
    }
}

Output

Attempted to divide by zero.

Thursday, April 10, 2014

Introduction to Visual Studio and Templates




Visual Studio
Microsoft Visual Studio is an Integrated Development Environment (IDE) created by Microsoft Corporation for Application Development. This IDE is used to develop console and windows applications run able only in Windows Platform. It is also used to develop web application also. Visual Studio 2008 is one of the versions of Visual Studio. Some other versions are Visual Studio 2005 or Visual Studio 2010 or Visual Studio Team System.
Visual Studio provides some features to its users. Some of these are:
·         Code editing
·         Debugging the code
·         Designing the User Interface
·         Some helping tools
·         Extensibility
Visual Studio has some built-in language compilers integrated in it. The main languages are C# and Visual Basic. But one can create any application in another language such as J#, C++ etc.
Templates
Visual studio project and item templates provide reusable and customizable project and item stubs that accelerates the development process, removing the need to create new projects and items from scratch.
Depending on the instance of the Visual Studio, generally there are 2 types of templates we can see. They are:
·                                  Project templates
Windows
Web
Smart Device
 Office
 Database
 Reporting
Test
WCF
Workflow
·                                  Item templates
 General
 Web
  Script

How To Create a Hello World in a Console Application using C# dotnet with Visual Studio




In this section i will create a small application . this application show only "Hellow world " into the console .

Steps:
  1. Start Microsoft Visual Studio 2008
  2. Click File>New>Project
You will see the following window.

3. Select Windows>Console Application   

4.Write appropriate name in ‘Name’ box, change the destination folder of the project directory by clicking the ‘Browse’ button  

5. Click OK button
6. Then you See The Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WalkThrough1
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}



     7 . Then Write The following Code inside the Main Method :
             Console.WriteLine("Hello world");
               Console.ReadKey();
     8. Now Press F5 to Run This .
    9. Then You Can See The  Output in Black Screen .