Exceptions.
We have the same code.
When i type
4/3
my program crashes with the error (picture).
When my colleague types 4/3
he gets it written to the output and the program continues. Why?72 Replies
how are you handling that exception
assuming you colleague is handling that and prints the message to console
I have no idea how if i'm being honest.
My understanding was that when the exception encounters a throw statement the program should crash (which it does for me)
Especially since ZZZZZZZ covered this for me yesterday and explained it
exception encounters a throw statementyour exception doesnt encounter anything its just an object
Right but he is throwing an exception which to me says (oh an error CRASH THE PROGRAM)
Considering it's unhandled
well, it should tell you "oh no something bad happened, I cant solve this!"
and if noone can, thats unhandled -> crash program
Yeah but he isn't handling it anywhere
He is just throwing the exception
I do know you have quite a bit of number parsing in your program thou
thats all culture dependant
Yes
else if(decimal.TryParse(token, out decimal number) == true)
{
throw new InvalidOperationException();
}
But shouldn't this just
crash the program?Β―\_(γ)_/Β―
we cant tell from that point
you might have a try catch later on
We don't
you are not running the exact same code then
he deffo has a try/catch or an unhandled exception handler
remember, the try/catch can be anywhere above in the callstack
breakpoints are your friend
Because your if statement should check if the result is false, I guess?
I don't see the logic in throwing if the parse succeeded
Also, if you're going to throw you might as well use
decimal.Parse
unless you want to be more specificI haven't written any of that code, so i have no idea
Oh, this is identical code on both sides?
I'm just trying to figure out why he gets it written to console and the program continues while mine crashes becuase an unhandled error.
Yes
Can you share the full code?
Preferably also from the other person
How?
Then just paste the code
Or a Github repo
OK seems he hasn't posted his changes
Our fork have different files for some reason
Probably a good idea to merge those changes then
How?
I assume this is a fork of another project you don't have control over, and that one has new changes?
Or what is a fork here?
I own the fork
It's my project
He has pushed changes
which i don't see in the software fork
And you work on the same branch, being
main
?
Or at least, I don't see other branches hereI'm unsure what branch mean
But i assusme so?
We work on the same project
You seem to be on the main branch together
A branch is part of your project and it's a version of it basically
You can work in a branch and make changes, and these changes exist on this branch
In that case, yeah
You can make more branches, and these will base off another branch as it is at that moment
So the main branch always exists
Then you make one called
Merineth
The other person makes changes to main, but these don't appear in Merineth
When you merge main to Merineth
, you merge its current state with your branch
I suggest you look up how these work
Anyway, the main issue here is conflicts
Right now you work on the same branch, on the same code
The issue here is that one change from somebody else might conflict with yours since you work on the same branch
Resolving this is annoying
Instead, what you should do it create a branch for each personAhhh
Depending on the company they might tell you to make one for each distinct feature, but it's up to you
Generally, a project has the main branch, and then a dev branch that was made from it
I think this is for school
Then this dev branch has a bunch of sub branches for each person
Again this depends entirely on what you want. People also often make a staging branch for example
but to add to this, using decent commit messages would also do you guys good
So what you should probably do is look into making two new branches from
main
, and work in those instead
Then, when you're done, you merge these with mainYeah i made them
But when we push
Once that is done, the other person can merge main into their branch
Conflicts will be way easier to resolve then, and you won't detatch your own branch constantly because it was modified elsewhere
I push from breanch merineth to origin/main
and he pushed from him to main?
I know this doesn't resolve your main issue, but it's so much easier to work on your project if you use branches properly
Merge requests (or pull requests if you use github) also very cleanly show you what was changed
Ok i made the two branches
He does not see them yet
How does he see them?
Fetch?
Yes
If you are on a branch and you fetch, it will look for new commits on that branch
Then, you
pull
You can also just pull immediatley
Difference is that fetch doesnt apply the changes immediatley
Considering you seem to work on the same files I suggest you try to pull and merge as much as possible to avoid possible conflicts
If you don't then it's not as necessary, but Git can complain quicklyYeah i'm just waiting for him to respond..
He clicked "fetch" and says he doesn't see them
Make sure the correct branch is currently chosen
What's the difference between branch and remote?
you mean this?
Like we got it almost to work
but i still dont understand what the difference is between branches and remotes
Are branches copies of the project ?
And then we merge them to main?
remote branch is just the branch in the remote repository
Yeah, if something is specified as remote then it's state state as it is in GitHub in your case
Ok
So currently i've pushed to main?
Because i specifically choose my branch.
We can see "Merineth" and Yannick" very far down
I'm desperate for some help at this point
:catHeyHello:
:sadcat:
Whats the current state?
I just want to understand the fork
"understand the fork"?
I dont understand branches, remotes
oh, git
okay
so a
remote
in git is a remotely connected repository
usually things like github, gitlab, bitbucket etc
so for example, your project has a remote, which is your github repository.makes sense
git works entirely offline locally
so when you "push", you actually push your local commits to the remote repository
a branch is... well, okay, now we need to talk about how git works
and i cba writing, wanna go on a call?
ok
If i want to output a custom message. Any advice on how that is achieved?
I want to basically achieve this
Would i have to create a user defined exception for
InvalidOperationException
and InvalidtokenException
?Yes
Or pass a message in when you throw it, if the exception allows it