Can we write like this try without providing catch
Like for example
try
{
}
Finally
{
}
Printable View
Can we write like this try without providing catch
Like for example
try
{
}
Finally
{
}
yes, most definately
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.
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
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
we have have try without catch block
Yes we can have the try without catch
Yes
1) We can have try without catch but Finally is mandatory
2) We cannot have catch without try
A try block should be with a single Catch block or Finally block or both .
[QUOTE=dvsriram;56092]A try block should be with a single Catch block or Finally block or both .[/QUOTE]
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");
}
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 .