C
C#2y 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
phaseshift2y ago
ok
Angius
Angius2y ago
$code
MODiX
MODiX2y 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
annoyingbOP2y ago
try
{
return (T)Convert.ChangeType(obj, typeof(T));
}
catch(InvalidCastException)
{
continue;
}
try
{
return (T)Convert.ChangeType(obj, typeof(T));
}
catch(InvalidCastException)
{
continue;
}
phaseshift
phaseshift2y ago
well, that catch will catch invalid cast exception, so the problem is something else, or you didn't re-build
annoyingb
annoyingbOP2y 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
phaseshift2y ago
look at the call stack then
Angius
Angius2y ago
As a side note... why Mono...?
annoyingb
annoyingbOP2y ago
what else? coreclr made no sense to me
Angius
Angius2y 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
annoyingbOP2y 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
Angius2y 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
annoyingbOP2y ago
oh well are there any docs that are simple and make sense?
Angius
Angius2y ago
Microsoft's docs?
Angius
Angius2y 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
annoyingbOP2y ago
where do i find how to use the coreclr?
Angius
Angius2y ago
What do you mean?
annoyingb
annoyingbOP2y ago
so i can use c++ with c#
Angius
Angius2y ago
yep
annoyingb
annoyingbOP2y ago
it's too confusing i'd rather use mono
Angius
Angius2y ago
It started being confusing the moment you said you want to use C++ with C# lmao
annoyingb
annoyingbOP2y ago
yeah but mono is really simple to get to work unlike the coreclr which looks like writing c# code in c++
Angius
Angius2y ago
Just write C# code and skip the C++ part
annoyingb
annoyingbOP2y ago
what do you mean?
Angius
Angius2y ago
Why do you need to use C++ with C#?
phaseshift
phaseshift2y ago
Why are you talking about c++ in the first place? Just use c# with ".net"
Angius
Angius2y ago
What do you need it for that you can't do with C#?
annoyingb
annoyingbOP2y ago
i want to learn how to use c# and c++ together
Angius
Angius2y ago
Why
annoyingb
annoyingbOP2y ago
because i want to learn
phaseshift
phaseshift2y ago
then learn one thing first
annoyingb
annoyingbOP2y ago
pinvoke didn't go too well :\
Angius
Angius2y ago
With an obsolete framework Lemme go learn cave painting right quick Will make me more desireable on the job market
annoyingb
annoyingbOP2y 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
Angius2y ago
So, I assume you already know C++ and C# well?
annoyingb
annoyingbOP2y ago
yeah
Angius
Angius2y ago
You not knowing about .NET makes me doubt that a little, but aight, go ahead and create your chimera of a project
annoyingb
annoyingbOP2y ago
ok
jcotton42
jcotton422y ago
@youdontknowwhoiam what specially does Mono do better wrt C++ interop than the CoreCLR? *specifically
Jimmacle
Jimmacle2y ago
i think he's talking about hosting the CLR within a C++ application
annoyingb
annoyingbOP2y ago
yeah i am
Accord
Accord2y 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