Error Handling
Prev Chapter 4. Generated C# Source Code Overview Next

Error Handling

As noted elsewhere in this manual, the asn1c runtime and generated code will throw exceptions that are, or derive from, Asn1Exception. The exception tells you what was wrong and provides a stack trace. If you need additional information you may try the following:

  • Identify the byte location in the input data using Asn1DecodeBuffer.ByteCount.

  • Identify the problem element using element name tracking. The procedure to do this is simple:

    1. Add "-events" to your asn1c command line. This is necessary for element name tracking to work.

    2. Obtain an Asn1Context object from your encode/decode buffer using Asn1MessageBuffer.Context.

    3. Enable element name tracking before encoding/decoding by invoking Asn1Context.EnableElementTracking().

    4. Get the name of the problem element by invoking Asn1Context.GetCurrentElement() inside your exception handling code.

    Element name tracking is demonstrated in the sample Writer in sample_ber/EventHandler.


Prev Up Next
Inner Classes Home Chapter 5. ASN.1 Type to C# Class Mappings

AltStyle によって変換されたページ (->オリジナル) /