Is there a way in C# to catch any kind of exception? Like in C++ to catch any kind of exception the format is like
try{
//Statements
}
catch(...){
// Some more statements
}
But this format in c# fails. Help?
Is there a way in C# to catch any kind of exception? Like in C++ to catch any kind of exception the format is like
try{
//Statements
}
catch(...){
// Some more statements
}
But this format in c# fails. Help?
You can catch anything like :
catch {}
From .NET 2 and further, this is equivalent to:
catch(Exception ex) {}
Because every exception (even a Windows SEH exception) is guaranteed to be derived from System.Exception
.
try {
// Statements
} catch (Exception ex) {
// Do stuff with ex
}
That should work.
Check this link out. It's all about exceptions.
What you are trying to do is use a parameter-less catch like this:
try {
// your code
} catch {
// any exception
}
The .NET framework provides a mechanism to detect/handle run time errors. C# uses three keywords in exception handling: try
, catch
, finally
. The try
block contains the statement that can cause an exception. The catch
block handles the exception, and the finally
block is used for cleaning up.
try
{
//statements that can cause an exception
}
catch(Type x)
{
//statements for handling an exception
}
finally
{
//cleanup code
}