Loop through Error
-
try { some code } catch(Exception ex) { some code } How can I loop with "forEach" statement through all exceptions ?
-
??? a catch block only catches one Exception. Why do u whant to loop and where? I don't understand your request spif2001
-
try { some code } catch(Exception ex) { some code } How can I loop with "forEach" statement through all exceptions ?
hi, As was already mentioned, catch "catches" only one Exception. I think you are trying to do something like :
try { //some code if(stg) { myBadFunctionThrowsMySpecificExcpetion(); } else { i= i/0; // throws another exception } } catch(MySpecificException ex) { // handle my specific exception } catch(Exception ex) { // handle generic exception (in this case divide by zero) }
When exception is raised intry
block, it is catched in "closest"catch
if throwed exception is (in meaning that operatoris
would return true - same type or derived class) the same as declared incatch
block. If exception of diferent type is thrown, then it passes thru firstcatch
block to another (if present),.. etc. You must write catch blocks from specific to most generic; if you wrote catch for System.Excpetion first, all exceptions would be handled in this block. No other would have chance to trap error. I only hope this is answer to your question :) best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.) -
hi, As was already mentioned, catch "catches" only one Exception. I think you are trying to do something like :
try { //some code if(stg) { myBadFunctionThrowsMySpecificExcpetion(); } else { i= i/0; // throws another exception } } catch(MySpecificException ex) { // handle my specific exception } catch(Exception ex) { // handle generic exception (in this case divide by zero) }
When exception is raised intry
block, it is catched in "closest"catch
if throwed exception is (in meaning that operatoris
would return true - same type or derived class) the same as declared incatch
block. If exception of diferent type is thrown, then it passes thru firstcatch
block to another (if present),.. etc. You must write catch blocks from specific to most generic; if you wrote catch for System.Excpetion first, all exceptions would be handled in this block. No other would have chance to trap error. I only hope this is answer to your question :) best regards, David 'DNH' Nohejl Never forget: "Stay kul and happy" (I.A.)You are close to the problem, but i want get all error messages from all risen errors there. In the last message I have wrote an example for SQL tasks. Here it works, because you can assign a specific error, so I think it shpuld be possible to loop within all possible errors ( I need the name for the element and elements-> foreach(element in elements))
-
You are close to the problem, but i want get all error messages from all risen errors there. In the last message I have wrote an example for SQL tasks. Here it works, because you can assign a specific error, so I think it shpuld be possible to loop within all possible errors ( I need the name for the element and elements-> foreach(element in elements))