C# Exception Catching using try..catch blocks -



C# Exception Catching using try..catch blocks -

i new c# , wanted gain improve understanding of exception catching. these questions may stupid noob questions. of import me , apologize in advance.

for example, in system.io path class, getfullpath, there 5 exceptions can thrown: argumentexception, securityexception, argumentnullexception, notsupportedexception, , pathtoolongexception. understand grab blocks must organized specific exception caught first , general exception caught last.

question 1: when msdn provides info on possible exceptions thrown class, how know exception specific , to the lowest degree specific? in other words, how determine exception order specific to the lowest degree specific msdn gives me?

question 2: need grab exceptions explicitly or using general exception grab other exceptions well? example, still using path class, need ...

try { ... } catch(system.argumentnullexception ane) { ... } catch(system.notsupportedexception nse) { ... } catch(system.io.pathtoolongexception ple) { ... } catch(system.io.securityexception se) { ... } catch(system.argumentexception ae) { ... }

or simple ...

catch(system.argumentexception ae) { ... }

catch of exceptions?

question 3: right syntax construction next in bool method ...

try { ... ; homecoming true; } catch(system.argumentexception ae) { ... ; homecoming false; }

question 1:

in msdn documentation each exception can see inheritance chain. tells ones more specific (the lower downwards chain they more specific).

you can see info in visual studio object browser.

question 2:

it practice grab exceptions can about. if can't reasonably exception, allow bubble up.

in general, tt improve grab more specific exceptions first.

you want @ different inheritance chains , decide exceptions want catch. example, doing:

catch(system.argumentexception ae) { ... }

will not grab system.io.securityexception system.io.securityexception doesn't inherit system.argumentexception.

question 3:

yes, valid syntax.

i wouldn't practice though. if exceptional situation, improve allow exception bubble up. suggested design cause exception ignored , whoever programming against method need check homecoming value (which might forget).

c# exception-handling try-catch block

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -