answersLogoWhite

0

Can a try block have more than one catch block?

Updated: 6/21/2021
User Avatar

Wiki User

11y ago

Best Answer

It can have as many as you want. It allows you to catch very specific exceptions.

--

Ac352 Answer

Having more than one catch statement is a bad idea. A better approach is to analyze the error and go from their. Here is an example.

Try

My.Computer.FileSystem.DeleteFile("C:\TEST.txt")

Catch ex As Exception

If ex.Message.Tostring="C:\TEST.txt Is An Invalid File Location" Then

'Do what you want to do.

End If

End Try

That is the best way just keep adding ElseIf statements to cover all exceptions that you want to find.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can a try block have more than one catch block?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How many catch bolock in single try block?

Usually one or more, though I guess a block with no catch block would also be valid in theory.


On Pokemon Yellow how can you catch more than one Mewtwo?

You cannot catch more than one Mewtwo. The only way to have more than one is through trading with someone else with the game.


Can you catch more than one rotom?

No. You can only catch Rotom once.


How do you use try block in cpp?

A try statement is used in conjunction with one or more catch blocks to provide exception handling. If an exception is thrown by a try block, the corresponding catch block will handle the exception. If no catch block is provided for a particular exception, then a runtime error occurs instead. Try-catch statements are used to provide graceful resolutions to potential runtime errors.


How many catch blocks can you use with one try block with example?

A try block can have multiple catch blocks, each handling a different type of exception. Be careful about the order of laying the exceptions. Using Exception at the top will catch everything that is derived from it, thereby missing the other specfic exception catches. And there can also be only one finally block.


How many finally block can be used for an exception handler?

Genaerally every try block maintain the one finally block or atleast one catch block or both. It mean try { try{ try{ } or } or } finally { catch(....) { catch(...){ } } } catch(.....) { : } finally{ : } Hear whenever we declar the try block without catch or finally bocks it show the compile time error like ' try without catch or finally' and also it is not possible to declare the any statements in between the try ,catch and finally blocks. ex: try{ } System.out.println("statement"); finally { } The above example show the compile time error 'try without catch or finally'. " Hear the finally block must be execute after excuting the try or catch block. Hence the finally block is used to release the resources like closing the streams and closing the jdbc connections." Hence in exception handling we use one finally block for one try block to release the resources.


Can a human have more than one virus at a time?

I do think that a person can have more than one virus at a time because if you are in a very contaminated area then you can catch more than one virus


How do catch more than one Dialga?

You cannot, there is only one in the game (unless you trade).


Which one is more easy to catch fire straws or wood?

It is very interesting to find out that straws are actually more easily to catch fire than wood...!


Can you catch more than one Lugia in soul silver?

No. Lugia is a legendary, which means there is only one of them.


How do you get 200?

to catch 200 Pokemon you have to have buy 400 (because it takes more than one throw) Pokeballs go catch them!


Which has a greater mass a large block of plastic or a small block made of the same plastic?

The large block has more mass than the small one. Same principle with rocks.