hmm problem is the variable is TextReader "myvariable" = new StreamReader(); , this is wrapped in the first try block...then how would you refer to myvariable in the next try block as it is out of scope?
Try-block is the segment for you code to execute safely. This is in-order to eliminate program crush if exception occurs at runtime. The Catch-block is segment to execute in case exception thrown by the runtime environment.
Every mature code must have a catch segment to trap the unexpected exception thrown. Through this segment, programmer can mitigate the program from crushing and do error-handling to provide reliable solution. Do not forget the finally-segment. This segment is executed on both occasions, on exception and on normal execution. It is good to start practicing this segment.
private static Object DoSomethingFunction()
// Declare the return object here.
// But don't intialize it. You may not know
// what lies in the constructor.
// Perform the intialization here.
p_result = new Object();
// On runtime error, exeception will be thrown.
// Set result and other resources to null or
// error handling state.
p_result = null;
// Do common resource clean-up before
// leaving the function. Usually good practice
// to release resource before exinting.
It is necessary to start each module with Try-Catch.
I am working creating a fully encapsulated, homogeneous singly linked data structure. The Listing class and SinglyLinkedList class that are part of the whole application compile fine, but the problem ...