cap5lut
Help me with C++ / C#
@Siegthis sounds a lot like u want to write some unit or integration tests.
the question is what u really want to test.
use the .NET test frameworks to test the C# side.
use whatever c++ provides to test their side.
testing the interoperability will become quite a big task
17 replies
Help me with C++ / C#
basically for what you are looking for u are most likely need to host the runtime inside ur native code, unless u want to restrict urself to NAOT compiled libraries/programs, which itself is explained there:
https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting
and thats just a starter; you will need to read the whole (or at least most of the) "Native interoperablity" section
17 replies
Help me with C++ / C#
secondary u have to take into account, that C# (or .NET) uses garbage collection instead of explicitly freeing memory.
and at that a compacting one, thus on the C# side, the addresses of references could change and make them invalid, if they were created on the C# side.
17 replies
Exception Handling in C#
(as a side note, there is actually a third kind of exception: the uncatchable, these u will not see unless u do something unsafe that is close to the system, its the kind of problems where the process itself can not recover from)
85 replies
Exception Handling in C#
there are in the end 2 kinds of exceptions,
one that indicate bugs (like
ArgumentException
, NullReferenceException
) which u usually do not catch (or only catch them to log what went wrong)
the other kind is failure that is outside of ur control (eg the internet connection died because ur wifi sucks, or the human ripped out the usb stick while u write to that file)85 replies
Exception Handling in C#
when to throw exceptions is quite use case dependent.
ur math example: this is a bit more complex because the existence of
NaN
, its a value to indicate that an operation wasnt possible, without throwing.
thats because often u have quite complex computations going on there and then check at certain points if its NaN
to see if there is a failure (u dont want a try catch block for every division, do ya?)
for the age of a person: as with each other, this type should maintain a stable state, because a negative age isnt possible, its the callers fault to provide the wrong values and it should throw an exception (an ArgumentOutOfRangeException
in this case)85 replies
Exception Handling in C#
basically u want the state of ur class/type to be valid all the time,
lets assume the
DoSomethingThatMightThrow()
method modifies ur internal state.
due to the exception that state would become invalid the next time it is used, but catch the exception, fix the internal state to make it valid again, but still provide the caller with the exception of what went wrong85 replies