-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the code on throwing exceptions #52
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Now `raiseError` and `raiseErrorMsg` uses `Throwable` class for the parameter type instead the `Exception` class. * Change all parameter names. * Update the javadocs. * Remove some unnecessary imported classes.
* Added new variable that stores exception named "cause" with `Throwable` identifier (so it can be used by any exception classes). This improve readability and reducing code for the exception blocks, by storing specific exception and then get thrown if the variable that stores exception is not null, passes it otherwise.
The `cause` itself will stores the exception temporarily and get thrown later.
Also remove unused else-if block that checks the `selectedIndex` is negative value or not (negative means the user haven't called `select(int)` yet), this check would never run because to checks the user has select any index row it uses `hasSelect` instead.
This changes included: * sum(Matrix) * sum(double[][]) * sum(Matrix, Matrix) * sum(double[][], double[][])
This changes included: * sub(Matrix) * sub(double[][]) * sub(Matrix, Matrix) * sub(double[][], double[][])
This changes included: * mult(Matrix) * mult(double[][]) * mult(Matrix, Matrix) * mult(double[][], double[][]) * mult(double) * mult(Matrix, double) Note: The last two is methods that perfoms scalar multiplication.
This changes included: * transpose() * transpose(double[][]) * transpose(Matrix)
mitsuki31
added
enhancement
Enhancing existing features
lang:java
Some changes on Java code
patch
Patch update
labels
Jun 23, 2023
This changes included: * display() * display(int) * display(double[][]) * display(double[][], int) Also change the message to display the null or empty two-dimensional array, its changed into "<null_2darray>".
This changes included: * isSquare() * isSquare(double[][]) * isSquare(Matrix) * isDiagonal() * isDiagonal(double[][]) * isDiagonal(Matrix) * sort() * sort(double[][]) * sort(Matrix)
mitsuki31
commented
Jun 24, 2023
* @see java.lang.Throwable | ||
* @see java.lang.Throwable#printStackTrace | ||
*/ | ||
final public static void raiseError(final Throwable cause) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the raiseError
parameter from Exception ex
to Throwable cause
, so it can be used by any type of exceptions either RuntimeException
and Exception
.
This also changed on these following methods:
raiseError(Exception, int)
->raiseError(Throwable, int)
raiseErrorMsg(Exception)
->raiseErrorMsg(Throwable)
raiseErrorMsg(Exception, int)
->raiseErrorMsg(Throwable, int)
mitsuki31
changed the title
Improve the code on catching exceptions
Improve the code on throwing exceptions
Jun 24, 2023
From `v1.0.0` to `v1.1.0`
From `v1.0.0` to `v1.1.0`
From `v1.0.0` to `v1.1.0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's Changed
Options.java
Changed the parameter on
raiseError
andraiseErrorMsg
methods. More details.Comparison
Matrix.java
cause
withThrowable
as identifier type.try-catch
blocks on several methods.Commits
raiseError
andraiseErrorMsg
(a59ca9d)cause
as private attribute (ff14d89)cause
variables (7c576a3)create
method (79cf264)select
method (c7a7ff4)change
method (2f37a56)sum
methods (0857039)sub
methods (b67f3a7)mult
methods (5ebc23f)transpose
methods (9f95d4d)display
methods (304a555)get
method (ff6a18f)Description
Added new (private) attribute named
cause
withThrowable
class as the identifier type.It's used to holds some exception that could occurs during runtime execution.
So, it makes the code more readable and flexible on catching and throwing the exceptions rather than
using
try-catch
blocks on everywhere, that makes code more dirty and maybe some peoplescan't understand it.
Removing the try-catch on some methods doesn't make it "a method with non-exceptions", instead it takes the exception and stores it into
cause
variable (which is private attribute) and then it checks whether thecause
is null, if no it will indicates thecause
stored some exception and will get raised immediately, otherwise passes it.Let's take a look this code example below.