I have defined a class in my code and a method within the class opens and reads a file. My question is:
I use a try/catch block when reading the file and if anything goes wrong (any exception is raised) my code uses Environment.Exit() to terminate the app. immediately. However, because I'm doing this file operation (try/catch and exit) in the class block, I'm not sure whether I'm doing the right thing at the right place.
Exiting within the class (in one of the methods) abruptly may cause memory problems or not? (because, as the app. exits within the class, the code haven't finalized -disposed- the class variable yet)
public class myClass : Object {
public bool LostSignificantFigures = false;
...
public myClass () {
bla bla ...;
}
~myClass () {
bla bla ...;
}
public void ReadData () {
try {
bla bla ...;
}
catch (Exception e) {
Environment.Exit (-1); // ??? exiting w/o finalizing?
}
}
...
...
...
static void Main (string [] args) {
myClass a = new myClass ();
a.ReadData ();
}
No comments:
Post a Comment