cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

How Do We Know Which Exceptions Each JLink Method Throws?

mark_stallard
1-Visitor

How Do We Know Which Exceptions Each JLink Method Throws?



Hi Everyone -

I'm updating a JLink application and want to apply specific handing
for each situation where reading a parameter might fail: The parameter
doesn't exist, the value doesn't have the expected type, and so on.

Of course, these statements are already surrounded by a try/catch
statement which catches the superclass jxthrowable, like this:

try {
Parameter param = model.GetParam( paramName ) ;

if ( param != null ) {
ParamValue valObj = param.GetValue() ;
value = valObj.GetStringValue() ;
} else {
value = " ;
}
} catch ( jxthrowable exc ) {
value = " ;
}

So what I want to do is create a separate catch statement for each
type of exception, like this:

try {
Parameter param = model.GetParam( paramName ) ;

if ( param != null ) {
ParamValue valObj = param.GetValue() ;
value = valObj.GetStringValue() ;
} else {
value = " ;
}
} catch ( XInvalidModelItem exc ) {
// Do something about a missing parameter
} catch ( XBadGetParamValue exc ) {
// Do something about a bad parameter value
} catch ( jxthrowable exc ) {
// Handle all other exceptions here
}

Unfortunately, I can't find any documentation that says which specific
exception each method might throw. The exception class names I used
in the catch statements above are just my wild guesses which exceptions
might be thrown

What I had hoped for was documentation that states which exceptions a
given might throw and the reason for doing so. This isn't an outrageous
expectation; Javadoc provides the @throws tag to document this information
in method's source code:


1 REPLY 1

Mark,

The general exception is jxthrowable, but decompiling the classes will show that some other exceptions can be thrown:

public void insertseq(int paramInt, Parameters paramParameters)
throws jxthrowable
{
if (paramParameters == null) {
throw XNullInNonOptArg.Create("arr");
}
CIPRemoteComm localCIPRemoteComm = CIPRemoteApp.getComm();
CIPTransport localCIPTransport = CIPRemoteApp.getTransport();
long l1 = localCIPTransport.obtainObjectPtr(this);
long l2 = localCIPTransport.obtainObjectPtr(paramParameters);
localCIPRemoteComm.sendCall();
localCIPTransport.sendInt(351);
localCIPTransport.sendObjectPtr(l1);
localCIPTransport.sendInt(paramInt);
localCIPTransport.sendObjectPtr(l2);
localCIPRemoteComm.processMessages();
}

But for reading a parameter value only jxthrowable is used when decompiling, but the manual says it will throw XBadGetParamValue. Hope the manual is correct.

public String GetStringValue()
throws jxthrowable
{
CIPRemoteComm localCIPRemoteComm = CIPRemoteApp.getComm();
CIPTransport localCIPTransport = CIPRemoteApp.getTransport();
long l = localCIPTransport.obtainObjectPtr(this);
localCIPRemoteComm.sendCall();
localCIPTransport.sendInt(279);
localCIPTransport.sendObjectPtr(l);
localCIPRemoteComm.processMessages();
return localCIPTransport.recvString();
}

All exception can be found in the API Wizard exception section, but they are not well related to methods.

I will suggest you use the ParamValue method Getdescr() to find out which getter method to use.

Best Regards,
Bjarne Frandsen
Announcements


Top Tags