Discuss Scratch

scratch978654
Scratcher
100+ posts

Try except and errors?

It would be nice to have osmething like python where you can handle errors such as

((5) / (0))

try
...


except <>
...
finally
...
end
Sorry not sure how to make C shape scratchblocks.

try:
print(1/0)
except ZeroDivisionError:
raise ZeroDivisionError
scratch978654
Scratcher
100+ posts

Try except and errors?

but it's also possible to work around:

to handle string division:

if <not <((thing) / (thing)) = [1]>> then
...
end

try:
print(1/0)
except ZeroDivisionError:
raise ZeroDivisionError
scratch978654
Scratcher
100+ posts

Try except and errors?

python equivalent:

try:
…..
except TypeError:
print(“TypeError”)
finally:
print(“done”)

try:
print(1/0)
except ZeroDivisionError:
raise ZeroDivisionError
A-E-
Scratcher
100+ posts

Try except and errors?

Would it be a block like this?
try {

} catch (error::custom) {

}::control
scratch978654
Scratcher
100+ posts

Try except and errors?

A-E- wrote:

Would it be a block like this?
try {

} catch (error::custom) {

}::control
yes. Not to mention the finally

try:
print(1/0)
except ZeroDivisionError:
raise ZeroDivisionError
Jeffalo
Scratcher
100+ posts

Try except and errors?

whats an example of an error you'd get?
A-E-
Scratcher
100+ posts

Try except and errors?

Jeffalo wrote:

whats an example of an error you'd get?
Division by zero, going off-stage, overflowing a cloud variable, passing a string rather than a number, etc.
Maximouse
Scratcher
1000+ posts

Try except and errors?

A-E- wrote:

Jeffalo wrote:

whats an example of an error you'd get?
Division by zero, going off-stage, overflowing a cloud variable, passing a string rather than a number, etc.
But division by zero is supposed to return infinity. Going off-stage definitely shouldn't be an error. Existing project may depend on strings being interpreted as 0 when a number is needed. So only overflowing cloud variables could be an error.

You are reading Maximouse's signature. Learn more about signatures
Click here to make pixel art.

Harakou wrote:

Yeah, this seems to be a request for custom reporter blocks - which has been suggested in the linked topic and a number of other times. I know I would personally love to see them, myself - I'm not sure what technical or design concerns there to them, if any.
scratch978654
Scratcher
100+ posts

Try except and errors?

Maximouse wrote:

A-E- wrote:

Jeffalo wrote:

whats an example of an error you'd get?
Division by zero, going off-stage, overflowing a cloud variable, passing a string rather than a number, etc.
But division by zero is supposed to return infinity. Going off-stage definitely shouldn't be an error. Existing project may depend on strings being interpreted as 0 when a number is needed. So only overflowing cloud variables could be an error.
what about

(item (-1 v) of [list v] :: list)

try:
print(1/0)
except ZeroDivisionError:
raise ZeroDivisionError
Maximouse
Scratcher
1000+ posts

Try except and errors?

scratch978654 wrote:

Maximouse wrote:

A-E- wrote:

Jeffalo wrote:

whats an example of an error you'd get?
Division by zero, going off-stage, overflowing a cloud variable, passing a string rather than a number, etc.
But division by zero is supposed to return infinity. Going off-stage definitely shouldn't be an error. Existing project may depend on strings being interpreted as 0 when a number is needed. So only overflowing cloud variables could be an error.
what about

(item (-1 v) of [list v] :: list)
Again, making these errors might break existing projects.

You are reading Maximouse's signature. Learn more about signatures
Click here to make pixel art.

Harakou wrote:

Yeah, this seems to be a request for custom reporter blocks - which has been suggested in the linked topic and a number of other times. I know I would personally love to see them, myself - I'm not sure what technical or design concerns there to them, if any.
Sheep_maker
Scratcher
1000+ posts

Try except and errors?

It could be somewhat similar to strict mode and ES classes in JavaScript where code in a try/except block could behave more strictly, but that might confuse some Scratchers

- Sheep_maker This is a kumquat-free signature. :P
This, my signature, appears below all my posts. Discuss it on my profile, not the forums. Here's how to make your own.
.postsignature { overflow: auto; } .scratchblocks { overflow-x: auto; overflow-y: hidden; }
A-E-
Scratcher
100+ posts

Try except and errors?

Sheep_maker wrote:

It could be somewhat similar to strict mode and ES classes in JavaScript where code in a try/except block could behave more strictly, but that might confuse some Scratchers
You mean like making it so errors are only thrown when inside a try block?
herohamp
Scratcher
1000+ posts

Try except and errors?

scratch978654 wrote:

A-E- wrote:

Would it be a block like this?
try {

} catch (error::custom) {

}::control
yes. Not to mention the finally
i have never understood the need for finally, just place your code under the try catch block of code

Last edited by herohamp (May 21, 2020 09:57:20)

Sheep_maker
Scratcher
1000+ posts

Try except and errors?

A-E- wrote:

Sheep_maker wrote:

It could be somewhat similar to strict mode and ES classes in JavaScript where code in a try/except block could behave more strictly, but that might confuse some Scratchers
You mean like making it so errors are only thrown when inside a try block?
Ye

herohamp wrote:

scratch978654 wrote:

A-E- wrote:

Would it be a block like this?
try {

} catch (error::custom) {

}::control
yes. Not to mention the finally
i have never understood the need for finally, just place your code under the try catch block of code
The finally block can be used to close streams I think. It's a bit weird, at least in JavaScript, because it runs after return statements in the try and catch blocks and it seems that errors in the catch block won't truly throw until the finally block is executed
function wow () {
  try {
    console.log('1')
    return error
  } catch (err) {
    console.log('2', err)
    return (console.log('3'), anothererror)
  } finally {
    console.log('4')
    eeee
  }
}
This logs 1, 2, 3, and 4, but throws a ReferenceError that eeee is not defined rather than anothererror

So with finally if you're dealing with some stream, you can return stuff in the try/catch blocks and then worry about closing the stream afterwards in the finally block

- Sheep_maker This is a kumquat-free signature. :P
This, my signature, appears below all my posts. Discuss it on my profile, not the forums. Here's how to make your own.
.postsignature { overflow: auto; } .scratchblocks { overflow-x: auto; overflow-y: hidden; }

Powered by DjangoBB

Standard | Mobile