Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot catch any InvalidAddressException from PLCExceptions.cs #484

Closed
dylandrush opened this issue Jun 16, 2023 · 2 comments
Closed

Cannot catch any InvalidAddressException from PLCExceptions.cs #484

dylandrush opened this issue Jun 16, 2023 · 2 comments

Comments

@dylandrush
Copy link

dylandrush commented Jun 16, 2023

When using DataItem.FromAddress(addr), it calls PLCAddress.Parse which can throw the exception InvalidAddressException. Either the exceptions from PLCExcpetions.cs should be public, or in this case, DataItem.FromAddress could wrap PLCAddress.Parse with a try/catch:

public static DataItem FromAddress(string address)
{
    try
    {
        PLCAddress.Parse(address, out var dataType, out var dbNumber, out var varType, out var startByte,
            out var bitNumber);
    }
    catch (InvalidAddressException ex) {
        throw new PlcException(ErrorCode.WrongVarFormat, ex);
    }

    return new DataItem
    {
        DataType = dataType,
        DB = dbNumber,
        VarType = varType,
        StartByteAdr = startByte,
        BitAdr = (byte) (bitNumber == -1 ? 0 : bitNumber)
    };
}
@mycroes
Copy link
Member

mycroes commented Jun 17, 2023

I guess they should all be public, I'm not even sure why they aren't in the first place... Feel free to submit a PR, otherwise I might be taking it up soon.

@mycroes
Copy link
Member

mycroes commented Jun 26, 2023

Sorry for the delay, just released v0.19.0 with this change to NuGet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants