Extending Try Catch
-
Hi Developers, I am using a group of statements in Try Catch Block. When an Error occured at any line of "Try Block" control goes to "Catch Block" and skip the execution of lines coming after Error Line. Now what I want is that "Program should start execution from line after the Error Line(Where error occurs)". I think there is some statement like Resume next is used in this case but not sure. Thanks in advance Lets work it Out.........!
-
Hi Developers, I am using a group of statements in Try Catch Block. When an Error occured at any line of "Try Block" control goes to "Catch Block" and skip the execution of lines coming after Error Line. Now what I want is that "Program should start execution from line after the Error Line(Where error occurs)". I think there is some statement like Resume next is used in this case but not sure. Thanks in advance Lets work it Out.........!
the only way to do this is to wrap a try..catch around each line individually. You can also nest try..catch blocks inside a master try..catch block to handle the real critical errors eg/
try try ' something error-prone catch MySpecificException ex ' do something catch MyCriticalException ex throw try ' something else error-prone catch MySpecificException ex ' do something catch MyCriticalException ex throw catch MyCriticalException ex ' handle critical exception
-
the only way to do this is to wrap a try..catch around each line individually. You can also nest try..catch blocks inside a master try..catch block to handle the real critical errors eg/
try try ' something error-prone catch MySpecificException ex ' do something catch MyCriticalException ex throw try ' something else error-prone catch MySpecificException ex ' do something catch MyCriticalException ex throw catch MyCriticalException ex ' handle critical exception
-
the only way to do this is to wrap a try..catch around each line individually. You can also nest try..catch blocks inside a master try..catch block to handle the real critical errors eg/
try try ' something error-prone catch MySpecificException ex ' do something catch MyCriticalException ex throw try ' something else error-prone catch MySpecificException ex ' do something catch MyCriticalException ex throw catch MyCriticalException ex ' handle critical exception
The flow of try catch block is when your code in try block occurs an error, it will do something in catch block. After that it will do something after catch block. So that:
SqlConnection connection = new SqlConnection( "ConnectionString" );
SqlCommand cmd = new SqlCommand( "CommandText", connection );
try {
connection.Open();
cmd.ExecuteNoneQuery();
}
catch {
// do something
}now you put each line in try block in try catch block like that:
try {
try { connection.Open(); } catch { // do something } try { cmd.ExecuteNoneQuery(); } catch { // do something }
}
catch {
// do something
}Do you understand now?