I'm working on a Sudoku solver in Java as a fun introduction to the language. One of the things I'm having my code do is check if the puzzle is solvable before it tries to solve it. I thought it would be a good idea to use try{} catch{} for this but I cannot get the code to compile.
public class SudokuSolver2 { public static void main(String[] args) { // 9x9 integer array with currentPuzzle // check current puzzle and make sure it is a legal puzzle, else throw "illegal puzzle" error try { // 1) check each row and make sure there is only 1 number per row // 2) check each column and make sure there is only 1 number per column // 3) check each square and make sure there is only 1 number per square throw new illegalPuzzle(""); } catch ( illegalPuzzle(String e) ) { System.out.println("Illegal puzzle."); System.exit(1); } } } public class illegalPuzzle extends Exception { public illegalPuzzle(String message) { super(message); } } Couple of questions...
Why won't the code compile in its current form?
Is there a way to write the code so that I do not have to use a "String message" parameter? All the examples I looked at use a string parameter but I don't really want it or need it.
Is there a way to write the code so that I do not have to create my own custom exception class? In other words, can I just throw a general error? All the examples I looked at created their own custom exception but I don't need that level of detail.
Thanks!
