Requirement is:
try
{
\\SQL Query
}
catch(Exception i)
{
print a
}
catch(SQLQueryException e)
{
\\SQL Query
}
Qu)I Got Exception in "try" block. Which "catch" statement
(i.e. 1st catch or 2nd catch ) catches the exception and
Why???
Answers were Sorted based on User's Feedback
Answer / parikshit
it will give compile time error as, the sequence of
exception class has to be Most Specific => General.
Is This Answer Correct ? | 12 Yes | 3 No |
Answer / sathish
There will be compile time error, becuase
the "..........catch(Exception ex)..........." is generic
exception block, where all type of exceptions are caught,
so when "catch(Exception ex)" is placed in the beginning,
then the following compile time error is thrown.
"A previous catch clause already catches all exceptions of
this or of a super type ('System.Exception')"
Is This Answer Correct ? | 10 Yes | 1 No |
Answer / meena
In try block the SQL query will be executed so the exception
will match the SQLException catch because all type of SQL
exception will be match in this SQLException
if we wrote normal query in try block then it will match
Exception catch
Is This Answer Correct ? | 5 Yes | 2 No |
Answer / sabir
when the exception is thrown it will search for mostly
likely to least likely exception so it will catch in second
catch
Is This Answer Correct ? | 11 Yes | 11 No |
Answer / mathew m
it will give error
previous catch clause already catches all exceptions of
this or of a super type ('System.Exception')
b"z System.Exception is the MOTHER -"mathaji" of all
exception.So all will be caught intitally,after that no
exception remains...it will be ok if we put child exception
like "SQLQueryException" before Exception [mathaji:)]
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / balakrishnan
The First Catch block will be executed, if the generic
exception should be defined it should be the last of
exception list
Is This Answer Correct ? | 0 Yes | 3 No |
Difference between <connectionstring> and <appsettings>
What are scaffold templates in mvc?
What is routeconfig.cs in mvc 4?
Explain bundle.config in mvc4?
What is meant by tempdata in mvc?
Microsoft introduced c# as a de facto language of the .NET platform. What is mean by de facto and fot what purpose? Please answer me. Advance thanks.
Which version of .net framework is installed?
What is Differnce between html.action and ajax.action?
Explain unit test done by tester on development team?
What is namespace of asp.net mvc?
Mention the core components of .net framework?
Can a view be shared across multiple controllers? If yes, how we can do that?