Exception Handling
EIP exception is promoted in the following 2 ways: | Exception method | Description | | --- | --- | | BceClientException | Client exception | | BceServerException | Server exception | Users can obtain the exception generated by an event with try, for example:
try {
eipClient.listEips();
} catch (BceServiceException bce){
System.out.println(bce.getMessage());
} catch ( BceClientException bce){
System.out.println( bce.getMessage());
}
Client Exception
Client exception represents the exception encountered when the client attempts to send a request to EIP and during data transmission. For example, when the network connection is unavailable at the time of sending request, ClientException is returned; and in case of IO exception during file upload, ClientException is also thrown.
Server Exception
In case of exception of EIP service end, EIP service end returns corresponding error information to users to locate the problem. For the common service end exceptions, please see EIP Error Code.
SDK Log
Logback is added in EIP Java SDK version as the realization of slf4j, and if you do not have your own realization for use directly, other log4j in the project (if any) can be used as substitution.
Default Log
If you use default logback, it needs to be configured in classpath of logback.xml. If there is no such configuration file, the log level is DEBUG by default.
<configuration>
<property name="LOG_HOME" value="./log/"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/EipUnitTest.%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>
Log Module
If you use their log realization module, for example, the project relies on Maven, it can be configured to pom.xml similarly as below to remove logback.
<?xml version="1.0" encoding="utf-8"?>
<dependency>
<groupId>com.baidubce</groupId>
<artifactId>bce-java-sdk</artifactId>
<version>${bce.sdk.version}</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>