Skip to content

Instantly share code, notes, and snippets.

@hackmajoris
Last active September 5, 2016 12:41
Show Gist options
  • Save hackmajoris/b6a27978309848517e75407f2c42536d to your computer and use it in GitHub Desktop.
Save hackmajoris/b6a27978309848517e75407f2c42536d to your computer and use it in GitHub Desktop.
Exception Handling
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test-group</groupId>
<artifactId>handle-exceptions</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
</project>
/**
* Created by viplord on 05.09.2016.
*/
import org.omg.CORBA.portable.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStreamReader;
public class Training {
private static final Logger LOG = LoggerFactory.getLogger(Training.class);
public void process(){
process1();
process2();
}
private void process1() {
InputStreamReader reader = new InputStreamReader(System.in);
reader = null; //for example
if(LOG.isDebugEnabled()){
LOG.debug("");
}
try {
reader.read();
} catch (IOException e) {
LOG.error(e.getMessage(), e);
} catch (RuntimeException e){
LOG.error(e.toString()+" check it");
}
}
private void process2(){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOG.error(e.getMessage(),e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment