bevarse Posted May 3, 2012 Report Posted May 3, 2012 bhayya .NET lo C# use chesi ila code cheyyavachha?? errors yemi levu but is it a good practice? try { Calling Method1; } catch (Exception ex) { try { Calling Method2; } catch (Exception ex1) { throw ex1; } throw ex; }
mammamiya Posted May 3, 2012 Report Posted May 3, 2012 exception catch chesinaka malli method enduku invoke cheyyadam mama i dont think this is right way of coding.....use separate try catch blocks
bevarse Posted May 3, 2012 Author Report Posted May 3, 2012 [quote name='mammamiya' timestamp='1336055728' post='1301731801'] exception catch chesinaka malli method enduku invoke cheyyadam mama i dont think this is right way of coding.....use separate try catch blocks [/quote] situation alantidi bhayya if method one fails method 2 should execute sucessfully
mammamiya Posted May 3, 2012 Report Posted May 3, 2012 c dis mama [url="http://stackoverflow.com/questions/7415099/how-do-you-call-a-method-from-a-catch-block-in-java"]http://stackoverflow.com/questions/7415099/how-do-you-call-a-method-from-a-catch-block-in-java[/url]
bevarse Posted May 3, 2012 Author Report Posted May 3, 2012 idi oka console application mamma code flow ila vundi static void Main(String[] args) try { method A } catch { } Private Void method A() { method B } Private Void method B() { method C } Private Void method C() { try { Calling Method1; } catch (Exception ex) { try { Calling Method2; } catch (Exception ex1) { throw ex1; } throw ex; } } so method C lo method1 error ichhina method2 should execute successfully seperate try catch use cheste after the first catch it is going back to the parent catch block
pikki Posted May 3, 2012 Report Posted May 3, 2012 [quote name='bevarse' timestamp='1336055850' post='1301731808'] situation alantidi bhayya if method one fails method 2 should execute sucessfully [/quote] if so write those methods with a return bool value... try { if(method1) { //do something } else { //do somethign (in your case method 2) } } catch (exception ex) { throw ex; } or you can use else if statements for multiple methods.. i think with the method you mentioned , if a proper catch block is hit it wont check for other exception (that is the other catch block) it will come out of the method.
soulmate Posted May 3, 2012 Report Posted May 3, 2012 [quote name='bevarse' timestamp='1336055546' post='1301731789'] bhayya .NET lo C# use chesi ila code cheyyavachha?? errors yemi levu but is it a good practice? try { Calling Method1; } catch (Exception ex) { try { Calling Method2; } catch (Exception ex1) { throw ex1; } throw ex; } [/quote] mama idhi baane undi kaane, Method 1 nd Method 2 fail aithe rendu exception ex1 and ex throw authai... ee method ki aa exception okkate throw cheyalante idi work avvadu, other than that it looks fine..
bevarse Posted May 3, 2012 Author Report Posted May 3, 2012 [quote name='pikki' timestamp='1336063168' post='1301732690'] if so write those methods with a return bool value... try { if(method1) { //do something } else { //do somethign (in your case method 2) } } catch (exception ex) { throw ex; } or you can use else if statements for multiple methods.. i think with the method you mentioned , if a proper catch block is hit it wont check for other exception (that is the other catch block) it will come out of the method. [/quote] method1 and method2 are void methods bhayya avi already coded by some one. manam marchadam avasaram aa? maa lead gaadu parti line inspect chesi appudu ok chestadu. ippudu anni maruste risk yemo ani
bevarse Posted May 3, 2012 Author Report Posted May 3, 2012 [quote name='soulmate' timestamp='1336065320' post='1301732870'] mama idhi baane undi kaane, Method 1 nd Method 2 fail aithe rendu exception ex1 and ex throw authai... ee method ki aa exception okkate throw cheyalante idi work avvadu, other than that it looks fine.. [/quote] Thanks mamma basically these methods are to write a file to a local folder. so rendu exceptions kalipi vachhina no prob.
Recommended Posts