Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ReliabilityContractAttribute

ReliabilityContractAttribute

Scheduled Pinned Locked Moved C#
helpquestionannouncement
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HosamAly
    wrote on last edited by
    #1

    Hello, I am trying to understand the CER feature, but I am not very confident that I understand it well. I have read a number of articles about it, but I still need to check whether I understand it correctly. I hope you could help me. First, I apologize for this long post. I thought it is necessary to clarify my question. I'm thankful for your patience. I am implementing a SafeHandle, and the release code looks like this:

    class MySafeHandle : SafeHandle {
    protected override bool ReleaseHandle() {
    MyClass.freeHandle(handle);
    return !MyClass.CheckErrors(false);
    }
    }
    class MyClass {
    internal static extern void freeHandle(MySafeHandle handle);
    internal static extern bool checkExternalErrors();

    internal static bool CheckErrors(bool throwExceptionOnError) {
        if (!checkExternalErrors()) return false;
        if (throwExceptionOnError) throw new Exception();
        return true;
    }
    

    }

    I'm not sure what to label freeHandle, checkExternalErrors and CheckErrors. freeHandle wouldn't tell whether there is an error; I have to call CheckErrors for that. But it will never throw an exception either, so I'm thinking it should be labeled [Cer.Success]. Meanwhile, CheckErrors may throw an exception, depending on the throwExceptionOnError parameter. So I think this should be labeled [Cer.MayFail]. But I don't really know... wouldn't that violate the CER on ReleaseHandle? Also what should I label checkExternalErrors? Does it not need a label? Or does it still need [ReliabilityContractAttribute(Consistency.WillNotCorruptState)]? I really feel confused! Thanks a lot for your patience! Even if you don't answer, I'm grateful that you read this post to the end. :)

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups