← Back to feed
Renewal·서른의 생활코딩

ex26) Java OOP - Collections

NS
normalstory
cover image




//exception handling

//this program by the compiler causes an error.
//that is the compiler a.txt file in case of occurs exception
//handling require
 
/*
import java.io.*;

class IOExceptionError {
public static void main(String args[]) {
FileReader file = new FileReader("a.txt");
// if a.txt file is not found?
int i;
while((i = file.read()) != -1) {
System.out.print((char)i);
}
file.close();
}
}**/




/*
import java.io.*;

class IOExceptionError {
public static void main(String args[]) {
try{
FileReader file = new FileReader("a.txt");
// if a.txt file is not found?
}
int i;
while((i = file.read()) != -1) {
System.out.print((char)i);
}
file.close();
}
}
**/


/*
import java.io.*;

class IOExceptionError {
public static void main(String args[]) {
try{
FileReader file = new FileReader("a.txt");//IOException
// if a.txt file is not found?
int i;
while((i = file.read()) != -1) {//IOException
System.out.print((char)i);
}
file.close();//IOException
}catch (Exception e) {
// TODO: handle exception !!!
System.out.println("all errorhandling");
}
}
}//Exception:errorhandling for,.

**/




/*
import java.io.*;

class IOExceptionError {
public static void main(String args[]) {
try{
FileReader file = new FileReader("a.txt");//FileNotFoundException
// if a.txt file is not found?
int i;
while((i = file.read()) != -1) {//IOException
System.out.print((char)i);
}
file.close();//IOException
}catch (Exception e) {
// TODO: handle exception !!!
System.out.println("all errorhandling");
}catch (FileNotFoundException e) {
// TODO: handle exception
System.out.println("correspondingfilenot found");
}catch (IOException e) {
// TODO: handle exception
System.out.println("I/Oerror");
}
}
}//Exception:errorhandling for,.
**/




/*
// multiple catch code block for using !!! -> inheritance reverse order writemust!
import java.io.*;

class IOExceptionError {
public static void main(String args[]) {
try{
FileReader file = new FileReader("a.txt");   // Exception object creation ->FileNotFoundException
// if a.txt file is not found?
int i;
while((i = file.read()) != -1) {             // IOException
System.out.print((char)i);
}
file.close();//IOException
}catch (FileNotFoundException e) {
// TODO: handle exception
System.out.println("correspondingfilenot found");        // -> here execution and program end!!!!
}catch (IOException e) {
// TODO: handle exception
System.out.println("I/Oerror");
}catch (Exception e) {                        
// TODO: handle exception !!!
System.out.println("all errorhandling");
}
}
}//Exception:errorhandling for,.
**/



/*
// only if 1 not 2's errorof case 2 immediately execution.
// however, when file.close(); executionnot being ->1's file open. 
import java.io.*;

class IOExceptionError {
public static void main(String args[]) {
try{
FileReader file = new FileReader("a.txt");   // Exception object creation ->FileNotFoundException
// if a.txt file is not found?
int i;
while((i = file.read()) != -1) {             // IOException
System.out.print((char)i);
}
file.close();//IOException
}catch (FileNotFoundException e) {
// TODO: handle exception
System.out.println("correspondingfilenot found");        // -> here execution and program end!!!!
}catch (IOException e) {
// TODO: handle exception
System.out.println("I/Oerror");
}catch (Exception e) {                        
// TODO: handle exception !!!
System.out.println("all errorhandling");
}finally{
System.out.println("erroroccurs presenceand regardless uncondition execution");
try{file.close();} catch (IOException e) {}
}
}
}//Exception:errorhandling for,.
**/





/*
import java.io.*;

class IOExceptionError {
public static void main(String args[]) {
FileReader file=null; //localvariable initial
try{
file = new FileReader("a.txt");   
// if a.txt file is not found?
int i;
while((i = file.read()) != -1) {             // IOException
System.out.print((char)i);
}
}catch (FileNotFoundException e) {
// TODO: handle exception
System.out.println("correspondingfilenot found");        // -> here execution and program end!!!!
}catch (IOException e) {
// TODO: handle exception
System.out.println("I/Oerror");
}catch (Exception e) {                        
// TODO: handle exception !!!
System.out.println("all errorhandling");
}finally{
System.out.println("erroroccurs presenceand regardless uncondition execution");
try{file.close();} catch (IOException e) {}
}
}
}//IOExceptionexecution ->nullpointException
**/






import java.io.*;

class IOExceptionError {
public static void main(String args[]) {
FileReader file=null; //localvariable initial
try{
file = new FileReader("a.txt");   
// if a.txt file is not found?
int i;
while((i = file.read()) != -1) {             // IOException
System.out.print((char)i);
}
}catch (FileNotFoundException e) {
// TODO: handle exception
System.out.println("correspondingfilenot found");        // -> here execution and program end!!!!
}catch (IOException e) {
// TODO: handle exception
System.out.println("I/Oerror");
}catch (Exception e) {                        
// TODO: handle exception !!!
System.out.println("all errorhandling");
}finally{
System.out.println("erroroccurs presenceand regardless uncondition execution");
try{file.close();} catch (Exception e) {}
}
}
}//Exception:errorhandling for,.






This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.