How to know which exception can be cast in C#?

Asked

Viewed 86 times

5

If in Java I invoke the method void cadastra() throws SQLException for example, I will be required to add a block try catch or to "relaunch" the exception that can be launched by this method.

That way, right off the bat I know which exception can be made.

Now, in C#, how do I know which exceptions to the method void Cadastra() can cast?

1 answer

4


Reading the documentation or using some tool that helps you know which exceptions can be thrown. Although this is not so accurate, why capture Exception it’s not a good idea.

If you’re going to relaunch the exception you’re doing something wrong, if you’re just going to relaunch it, don’t capture it. People capture a lot more exceptions than they should. They almost never manage to do anything useful with it. So let it propagate.

In Java too there is no way to know many exceptions and the ones that have are considered problematic in many situations even by most Java programmers who know what they are talking about.

For all this I think exception a wrong mechanism most of the time.

The Java engine that indicates an exception can be released is quite controversial and practice has shown that it brings more problems than solutions.

  • 2

    If there is something wrong, please inform me to improve.

  • Now that I see there’s a -1.. It wasn’t me.. I didn’t understand why

  • 1

    @Igorventurelli know not. Had another.

  • I think it’s people who love exceptions, and anyone who thinks outside the box and knows what exceptions are bad mechanisms deserves a negative. It’s the sad reality of our profession, people believe a lot in what’s popular, not what makes sense.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.