Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean in .Net: try-catch block without any Exception as parameter for catch?

What does it mean in .Net: try-catch block without any Exception as parameter for catch?

like image 780
odiseh Avatar asked Feb 18 '10 11:02

odiseh


People also ask

What happens if exception is not caught in try catch?

What happens if an exception is not caught? If an exception is not caught (with a catch block), the runtime system will abort the program (i.e. crash) and an exception message will print to the console.

What happens if exception occurs in Catch block C#?

catch – When an exception occurs, the Catch block of code is executed. This is where you are able to handle the exception, log it, or ignore it. finally – The finally block allows you to execute certain code if an exception is thrown or not.

Can exception be caught without catch block?

Yes, it is possible. You can use an uncaught exception handler. Its responsibility is to catch the exceptions that your program didn't catch, and do something with it.

What is an Catch exception?

Each catch block is an exception handler that handles the type of exception indicated by its argument. The argument type, ExceptionType , declares the type of exception that the handler can handle and must be the name of a class that inherits from the Throwable class. The handler can refer to the exception with name .


2 Answers

It's almost the same as catch (Exception ex), if you are not using unmanaged calls, because all exceptions in .NET derive from the Exception class. It is used when you don't need the instance of Exception in your catch block. But catch without Exception as a parameter will catch also unmanaged exceptions, because in other unmanaged languages exceptions may not be derived from the Exception class.

like image 104
Arsen Mkrtchyan Avatar answered Sep 28 '22 05:09

Arsen Mkrtchyan


It means the catch block will catch any exception.

It also means that you can't do anything with the exception object as you don't have a reference to it.

You may use this pattern when you genuinely don't care about anyexception occuring (and don't want to do anything with it), but generally you should avoid this style.

like image 20
Paolo Avatar answered Sep 28 '22 05:09

Paolo