Specman-e usage of try { };
题
I would like to know what the keyword try
is used for in Specman and especially its usage in the code snippet given below:
try {
unpack(packing.low,lob,pkt);
} else{
message(LOW, “Uh-oh!”){print lob using HEX;};
message(LOW,”bad unpack!!!”);
};
解决方案
try
and else
are Specman's exception handling constructs. If an error is created in the try
block, then the else
block is immediately executed instead of the rest of the try
block and the error is suppressed with no printout.
In this case, if lob
has more bits than pkt
has "physical fields", then the unpack will generate an error. If that happens, the Specman runtime will jump to the else
block and print out the lob
data structure instead of printing the original unpack
error. Look in the docs with regards to what "physical fields" are and how they are used. They are a strange construct that specifically interacts with the behavior of Specman's %
, pack
, and unpack
constructs. Physical fields of pkt
will be declared with the %
modifier preceding the "physical fields" of pkt
.
其他提示
try and if are similar where if executes the true block when the condition is true and else it executes the false. similarly try also if there is an error in the true block it switches to else block.