Is it possible to check in a program whether a given variable in a class in some other program is private or not by, for instance, using try and catch?
By that I mean one that I could include in the first program similiarly to libraries. Perhaps I shouldn't have called it an "other program" since it would lack the main function.
you can open the source code file and do a simple parse of it? (you have to track maybe 4 or 5 things... public and private keywords, class and struct keywords, and {} pairs related to the class and structs).
private is a language tool to prevent accidental access where it could produce bugs, and as said already it is a compile time error. Compiled libraries are a tricky subject as they may not even have originated in a language that has these concepts (public and private). Like C, for example, has no concept of private. Instead, a library is supposed to expose to the user what is allowed to be used, and all else is hidden simply via the limitation that anything not exposed is not (easily) accessible or even (known about?) without the source code behind it. If its not in the interface, its private :)