Try .. Catch with no Exception needed.

  • Thread starter Thread starter RP
  • Start date Start date
R

RP

In certain code blocks I don't want to do anything when an error is
raised. I simply want that application must remain stable instead of
crash. For the following code, is there a way to ignore declaration of
Exception ex:

try
{
//do somthing
}
catch (Exception ex)
{ //do nothing };

Since I am not using ex, it raises too many warnings.
 
Uzytkownik "RP said:
In certain code blocks I don't want to do anything when an error is
raised. I simply want that application must remain stable instead of
crash. For the following code, is there a way to ignore declaration of
Exception ex:

try
{
//do somthing
}
catch (Exception ex)
{ //do nothing };

Since I am not using ex, it raises too many warnings.

You can use :

try{
}
catch(Exception){
}

no warnings ;-)
 
The application will still crash. You need an empty 'catch' block, not an
empty 'finally' block. There is absolutely no case where an empty 'finally'
block would be useful.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++ VB Edition: VB to C++/CLI
Instant C++ C# Edition: C# to C++/CLI
 
It should be noted that if you catch an Exception (or just have a catch
statement) that your application won't necessarily be "stable". In catching
all exceptions (instead of just ones you know are going to be thrown) you
are corrupting your application state to some degree, and if you aren't
fastidious about defining the boundaries of your application, you will have
unexpected errors because of exceptions that were thrown and ignored in
other areas.

In other words, be very careful about proceeding in this manner. There
are reasons that exceptions are thrown, and you should ignore them at your
own peril.
 
Nicholas said:
It should be noted that if you catch an Exception (or just have a catch
statement) that your application won't necessarily be "stable". In catching
all exceptions (instead of just ones you know are going to be thrown) you
are corrupting your application state to some degree, and if you aren't
fastidious about defining the boundaries of your application, you will have
unexpected errors because of exceptions that were thrown and ignored in
other areas.

In other words, be very careful about proceeding in this manner. There
are reasons that exceptions are thrown, and you should ignore them at your
own peril.

For some reason an image of an old map popped into my head containing
"Here there be dragons!" :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top