How will you suppress error Message in Try catch block ?
How will you suppress error Message in Try catch block ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Apr 2, 2011, 12:08 PM
VulpesPosted Apr 1, 2011, 5:43 PM
Suthish NairPosted Apr 1, 2011, 5:33 PM
Same thing happens to me once :).
I asked what you mean by suppress the exception.
I was not able to answer what he wants.
But after the session i asked him about this.
He said, how to show user defined messages when exception occurs.
I got confused whats the relation that.
Anyway, Still am not sure that was the answer for that. But taut of sharing it here.
Suppress also means forcibly put an end to.
VulpesPosted Apr 1, 2011, 5:02 PM
If they'd asked me that question at an interview and told me my answer was wrong, that's exactly what I'd have told them!
Suthish NairPosted Apr 1, 2011, 3:09 PM
Suppress means how to avoid system generated errors and show user defined error messages.
For example, this not accurate but will give you an idea:
static void Main(string[] args) {
try
{
int x = 1;
int y = 0;
int z = x / y;
}
catch (Exception)
{
CatchErrors err = new CatchErrors();
//Console.WriteLine(err.Message);
Console.WriteLine(err.ShowErrors());
Console.ReadLine();
}
}
public class CatchErrors : Exception
{
public CatchErrors() { }
public void GetErrors()
{
throw new Exception();
}
public string ShowErrors()
{
return "Hello, You can't catch me out with that one!";
}
}
VulpesPosted Apr 1, 2011, 8:40 AM
As far as the 'catch' clause is concerned you don't need to display a message to the user but can simply handle the exception 'silently'.
Manikavelu VelayuthamPosted Apr 1, 2011, 8:15 AM
Because my friend tried the same answer when he got interviewed. But Interviewer argued there is some other way like that.
I too searched in google, but didnt get a valid point.
VulpesPosted Apr 1, 2011, 5:35 AM