Results 1 to 11 of 11

Thread: Try without catch

  1. #1
    Junior Member
    Join Date
    Jan 2006
    Answers
    1

    Try without catch

    Can we write like this try without providing catch

    Like for example

    try
    {
    }
    Finally
    {
    }


  2. #2
    Junior Member
    Join Date
    Jan 2008
    Answers
    2

    Re: Try without catch

    yes, most definately


  3. #3
    Junior Member
    Join Date
    Sep 2007
    Answers
    1

    Re: Try without catch

    Hi,

    I don't think that you can write a try block without catch in C#. You have to write the catch block when there is try block. However, finally is optional. If you want to process with any statements, you can do code them in finally block.


  4. #4
    Junior Member
    Join Date
    Jan 2008
    Answers
    1

    Thumbs up Re: Try without catch

    hai, you can't write try without catch.

    if you write any code between try and cacth block it will show you compilaion error. see below

    try
    {
    try block
    }
    <code>
    catch(Exception e)
    {
    catch block
    }

    when ever you are going to use try block you must define catch block also.

    so your are put the excpected code which going to be through the exception.

    if that doubtfull code through the exception who will catch the exception when doubt full code will raise the exception that try block will traminated and comtroller will come to catch block and it will excecute the catch block

    if you dont write the catch block you program will not compile means compiler will not allow you to compile you file try block with out catch block

    Last edited by santugadipelly; 01-26-2008 at 06:13 AM.

  5. #5
    Junior Member
    Join Date
    Jan 2008
    Answers
    2

    Re: Try without catch

    Yes, you can DEFINATELY have try block with out a catch, as long as you don't have code between the try and finally blocks


  6. #6
    Junior Member
    Join Date
    Dec 2009
    Answers
    1

    Re: Try without catch

    we have have try without catch block


  7. #7
    Junior Member
    Join Date
    May 2010
    Answers
    6

    Re: Try without catch

    Yes we can have the try without catch


  8. #8
    Junior Member
    Join Date
    Jun 2010
    Answers
    1

    Re: Try without catch

    Yes
    1) We can have try without catch but Finally is mandatory
    2) We cannot have catch without try


  9. #9
    Junior Member
    Join Date
    Jul 2010
    Answers
    2

    Re: Try without catch

    A try block should be with a single Catch block or Finally block or both .


  10. #10
    Junior Member
    Join Date
    Nov 2009
    Answers
    2

    Thumbs up Re: Try without catch

    Quote Originally Posted by dvsriram View Post
    A try block should be with a single Catch block or Finally block or both .
    This is perfect answer !!

    This code works
    ---------------------------------------------------
    try
    {
    MessageBox.Show("In Try");
    }
    finally
    {
    MessageBox.Show("In Final");
    }
    MessageBox.Show("OutSide Try-Finally");

    But not this
    ------------------------------------------------------
    try
    {
    MessageBox.Show("Only-Try");
    }


  11. #11
    Junior Member
    Join Date
    Feb 2011
    Answers
    1

    Re: Try without catch

    Yes. We can use try with out catch , but there is no use for that because catch block catches the exceptions in the code . If we are using try block we are just trying the executes or not .


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact