add error handle: ComponentException & PacketException

This commit is contained in:
free will committed 2021-03-24 11:14:54 +08:00
1 parent d7f063cbb9
commit 7bf0906291
35 files changed
+955 -362

No files matched your search

+38 -13
View File
@@ -68,7 +68,7 @@ public class Data implements IEncodingAble,InteractWithField {
* @return
*/
@Override
public boolean fillDataToFields() throws EncoderException, BlockException {
public boolean fillDataToFields() throws PacketException {
/////////////////////////////////////////////////////////////
//// 填充可变区
// { => 可变区
@@ -84,7 +84,12 @@ public class Data implements IEncodingAble,InteractWithField {
this.minPacket.mutableField.mutableProtectField.clearBlocks();
// CongestionMark
Block block=new SelfEncodingBase().selfWireEncode(this.congestionMark);
Block block= null;
try {
block = new SelfEncodingBase().selfWireEncode(this.congestionMark);
} catch (EncoderException | BlockException e) {
throw new PacketException("Data.fillDataToFields: "+e.getMessage());
}
if(block==null){
return false;
}
@@ -104,7 +109,11 @@ public class Data implements IEncodingAble,InteractWithField {
// FreshnessPeriod
if(this.freshnessPeriod.isInitial()){
block=new SelfEncodingBase().selfWireEncode(this.freshnessPeriod);
try {
block=new SelfEncodingBase().selfWireEncode(this.freshnessPeriod);
} catch (EncoderException | BlockException e) {
throw new PacketException("Data.fillDataToFields: "+e.getMessage());
}
if(block==null){
return false;
}
@@ -113,7 +122,11 @@ public class Data implements IEncodingAble,InteractWithField {
// NackHeader
if(this.nackHeader.isInitial()){
block=new SelfEncodingBase().selfWireEncode(this.nackHeader);
try {
block=new SelfEncodingBase().selfWireEncode(this.nackHeader);
} catch (EncoderException | BlockException e) {
throw new PacketException("Data.fillDataToFields: "+e.getMessage());
}
if(block==null){
return false;
}
@@ -121,7 +134,11 @@ public class Data implements IEncodingAble,InteractWithField {
}
// Payload
block=new SelfEncodingBase().selfWireEncode(this.payload);
try {
block=new SelfEncodingBase().selfWireEncode(this.payload);
} catch (EncoderException | BlockException e) {
throw new PacketException("Data.fillDataToFields: "+e.getMessage());
}
if(block==null){
return false;
}
@@ -146,7 +163,7 @@ public class Data implements IEncodingAble,InteractWithField {
* @return
*/
@Override
public boolean extraDataFromFields() throws VlIntException {
public boolean extraDataFromFields() throws PacketException {
/////////////////////////////////////////////////////////////
//// 解析可变区
// { => 可变区
@@ -160,8 +177,12 @@ public class Data implements IEncodingAble,InteractWithField {
/////////////////////////////////////////////////////////////
Block block=this.minPacket.mutableField.mutableProtectField.getBlockByType(new VlInt(TLV.TlvCongestionMark));
if(block!=null){
if(!this.congestionMark.wireDecode(block)){
return false;
try {
if(!this.congestionMark.wireDecode(block)){
return false;
}
} catch (ComponentException e) {
throw new PacketException("Data.extraDataFromFields: "+e.getMessage());
}
}
@@ -184,8 +205,12 @@ public class Data implements IEncodingAble,InteractWithField {
}
switch (type){
case TLV.TlvFreshnessPeriod:
if(!this.freshnessPeriod.wireDecode(newblock)){
return false;
try {
if(!this.freshnessPeriod.wireDecode(newblock)){
return false;
}
} catch (ComponentException e) {
throw new PacketException("Data.extraDataFromFields: "+e.getMessage());
}
case TLV.TlvPayload:
if(!this.payload.wireDecode(newblock)){
@@ -216,10 +241,10 @@ public class Data implements IEncodingAble,InteractWithField {
* @return
*/
@Override
public int wireEncode(Encoder encoder) throws EncoderException, BlockException {
public int wireEncode(Encoder encoder) throws PacketException {
// 首先将各项属性填充到分区当中
if(this.fillDataToFields()){
return 0;
return -1;
}
// 指定包类型
@@ -234,7 +259,7 @@ public class Data implements IEncodingAble,InteractWithField {
* @return
*/
@Override
public boolean wireDecode(Block block) throws VlIntException {
public boolean wireDecode(Block block) throws PacketException {
if(!this.minPacket.wireDecode(block)){
return false;
}