<commit_before>class Foo {
  def bar: x {
    (x == 'error) . if_true: {
      StdError new: "Some Error" . raise!
    } else: {
      'no_error
    }
  }
}

FancySpec describe: StdError with: {
  it: "should raise an exception and catch it correctly" for: 'raise! when: {
    try {
      StdError new: "FAIL!" . raise!
      nil should == true # this should not occur
    } catch StdError => ex {
      ex message should == "FAIL!"
    }
  }

  it: "should raise an exception inside a method and catch it correctly" when: {
    f = Foo new
    f bar: "Don't raise here" . should == 'no_error
    try {
      f bar: 'error . should == 'no_error
    } catch StdError => e {
      e message should == "Some Error"
    }
  }

  # it: "should raise a NoMethodError" when: {
  #   s = 'symbol
  #   try {
  #     s this_method_doesnt_exist!
  #     nil should == true # should not execute
  #   } catch NoMethodError => err {
  #     err for_class should == Symbol
  #     err method_name should == "this_method_doesnt_exist!"
  #   }
  # }

  it: "should have access to variables in exception handlers defined in the surrounding scope" when: {
    var = 1234
    try {
      var wont_work!
    } catch NoMethodError => err {
      var should == 1234
    }
  }

  it: "should always evaluate the finally clause" when: {
    try {
      x = 10 / 0 # ouch!
      "This should fail!" should == true # should not get here!
    } catch ZeroDivisionError => err {
      err message should == "divided by 0"
    } finally {
      # this part gets always run :)
      "It works!" should == "It works!"
    }
  }

  it: "should raise a StdError when raising a String" for: 'raise! when: {
    msg = "A Custom Error!"
    try {
      msg raise!
      msg should_not == msg # this should not get executed
    } catch StdError => e {
      e message should == msg
    }
  }

  # it: "should raise and catch a custom exception correctly" for: 'raise! when: {
  #   class MyError : StdError{
  #     def initialize {
  #       super initialize: "MyError message"
  #     }
  #   }

  #   try {
  #     MyError new raise!
  #     nil should == true # will fail
  #   } catch MyError => e {
  #     e message should == "MyError message"
  #   }
  # }

  it: "should restart itself after being fixed in a catch clause" when: {
    y = 0
    x = 0
    try {
      x = 10 / y
    } catch ZeroDivisionError => e {
      y should == 0
      x should == 0
      y = 2
      retry
    }
    y should  == 2
    x should  == 5
  }

  it: "should always execute the finally block when defined" when: {
    try {
      10 / 0 # ZeroDivisionError
    } finally {
      true should == true
    }
  }
}<commit_msg>Fixed spec to work as expected (tests/exception.fy).<commit_after>class Foo {
  def bar: x {
    (x == 'error) . if_true: {
      StdError new: "Some Error" . raise!
    } else: {
      'no_error
    }
  }
}

FancySpec describe: StdError with: {
  it: "should raise an exception and catch it correctly" for: 'raise! when: {
    try {
      StdError new: "FAIL!" . raise!
      nil should == true # this should not occur
    } catch StdError => ex {
      ex message should == "FAIL!"
    }
  }

  it: "should raise an exception inside a method and catch it correctly" when: {
    f = Foo new
    f bar: "Don't raise here" . should == 'no_error
    try {
      f bar: 'error . should == 'no_error
    } catch StdError => e {
      e message should == "Some Error"
    }
  }

  # it: "should raise a NoMethodError" when: {
  #   s = 'symbol
  #   try {
  #     s this_method_doesnt_exist!
  #     nil should == true # should not execute
  #   } catch NoMethodError => err {
  #     err for_class should == Symbol
  #     err method_name should == "this_method_doesnt_exist!"
  #   }
  # }

  it: "should have access to variables in exception handlers defined in the surrounding scope" when: {
    var = 1234
    try {
      var wont_work!
    } catch NoMethodError => err {
      var should == 1234
    }
  }

  it: "should always evaluate the finally clause" when: {
    try {
      x = 10 / 0 # ouch!
      "This should fail!" should == true # should not get here!
    } catch ZeroDivisionError => err {
      err message should == "divided by 0"
    } finally {
      # this part gets always run :)
      "It works!" should == "It works!"
    }
  }

  it: "should raise a StdError when raising a String" for: 'raise! when: {
    msg = "A Custom Error!"
    try {
      msg raise!
      msg should_not == msg # this should not get executed
    } catch StdError => e {
      e message should == msg
    }
  }

  # it: "should raise and catch a custom exception correctly" for: 'raise! when: {
  #   class MyError : StdError{
  #     def initialize {
  #       super initialize: "MyError message"
  #     }
  #   }

  #   try {
  #     MyError new raise!
  #     nil should == true # will fail
  #   } catch MyError => e {
  #     e message should == "MyError message"
  #   }
  # }

  it: "should restart itself after being fixed in a catch clause" when: {
    y = 0
    x = 0
    try {
      x = 10 / y
    } catch ZeroDivisionError => e {
      y should == 0
      x should == 0
      y = 2
      retry
    }
    y should  == 2
    x should  == 5
  }

  it: "should always execute the finally block when defined" when: {
    try {
      msg = "Reraise a new Exception :P"
      try {
        10 / 0 # ZeroDivisionError
      } finally {
        msg raise!
      }
    } catch StdError => e {
      e message should == msg
    }
  }
}
{'fraction_non_alphanumeric': 0.10774532922183928, 'fraction_numerical': 0.008706693270451659, 'mean_word_length': 1.9821525148729042, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2837269', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1758, 'n_words': 641}