C
C#15mo ago
annoyingb

❔ exception not being caught

I am converting a type with Convert.ChangeType() but I want to catch the invalid cast exception but it wont.
43 Replies
phaseshift
phaseshift15mo ago
ok
Angius
Angius15mo ago
$code
MODiX
MODiX15mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
annoyingb
annoyingb15mo ago
try
{
return (T)Convert.ChangeType(obj, typeof(T));
}
catch(InvalidCastException)
{
continue;
}
try
{
return (T)Convert.ChangeType(obj, typeof(T));
}
catch(InvalidCastException)
{
continue;
}
phaseshift
phaseshift15mo ago
well, that catch will catch invalid cast exception, so the problem is something else, or you didn't re-build
annoyingb
annoyingb15mo ago
i am using mono but i don't know if this interferes with the code running because it prints out that there was an exception
phaseshift
phaseshift15mo ago
look at the call stack then
Angius
Angius15mo ago
As a side note... why Mono...?
annoyingb
annoyingb15mo ago
what else? coreclr made no sense to me
Angius
Angius15mo ago
How did it not make sense? .NET is the cross-platform runtime There's zero reason to use Mono for any new project Unless you're trying to do some weird shit like running WPF on Linux
annoyingb
annoyingb15mo ago
the docs told me not to use some files but to run the code i needed the files and some files that i needed weren't mentioned. also, isn't coreclr still in development?
Angius
Angius15mo ago
Uh, no? Hasn't been for years Hell, it's no longer even named .NET Core Now it's just .NET Has been this way for 3 major versions already
annoyingb
annoyingb15mo ago
oh well are there any docs that are simple and make sense?
Angius
Angius15mo ago
Microsoft's docs?
Angius
Angius15mo ago
.NET documentation
Learn to use .NET to create applications on any platform using C#, F#, and Visual Basic. Browse API reference, sample code, tutorials, and more.
annoyingb
annoyingb15mo ago
where do i find how to use the coreclr?
Angius
Angius15mo ago
What do you mean?
annoyingb
annoyingb15mo ago
so i can use c++ with c#
Angius
Angius15mo ago
yep
annoyingb
annoyingb15mo ago
it's too confusing i'd rather use mono
Angius
Angius15mo ago
It started being confusing the moment you said you want to use C++ with C# lmao
annoyingb
annoyingb15mo ago
yeah but mono is really simple to get to work unlike the coreclr which looks like writing c# code in c++
Angius
Angius15mo ago
Just write C# code and skip the C++ part
annoyingb
annoyingb15mo ago
what do you mean?
Angius
Angius15mo ago
Why do you need to use C++ with C#?
phaseshift
phaseshift15mo ago
Why are you talking about c++ in the first place? Just use c# with ".net"
Angius
Angius15mo ago
What do you need it for that you can't do with C#?
annoyingb
annoyingb15mo ago
i want to learn how to use c# and c++ together
Angius
Angius15mo ago
Why
annoyingb
annoyingb15mo ago
because i want to learn
phaseshift
phaseshift15mo ago
then learn one thing first
annoyingb
annoyingb15mo ago
pinvoke didn't go too well :\
Angius
Angius15mo ago
With an obsolete framework Lemme go learn cave painting right quick Will make me more desireable on the job market
annoyingb
annoyingb15mo ago
but that is not what i am trying to do i'm not trying to get a job i just want to learn...
Angius
Angius15mo ago
So, I assume you already know C++ and C# well?
annoyingb
annoyingb15mo ago
yeah
Angius
Angius15mo ago
You not knowing about .NET makes me doubt that a little, but aight, go ahead and create your chimera of a project
annoyingb
annoyingb15mo ago
ok
jcotton42
jcotton4215mo ago
@youdontknowwhoiam what specially does Mono do better wrt C++ interop than the CoreCLR? *specifically
Jimmacle
Jimmacle15mo ago
i think he's talking about hosting the CLR within a C++ application
annoyingb
annoyingb15mo ago
yeah i am
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts