Tuesday, August 30, 2022

Free Alternatives to Heroku


I still remember my first Machine Learning project was deployed on Heroku. Today a message appeared on my mailbox telling all the Heroku free tiers are coming to an end. 





Heroku as a PAAS service provided so many features and runtime development throughout the year. From November 28, 2022 all the free tier will no longer be available in Heroku. As part of this, the free Heroku Postgres, and free Heroku Data for Redis will also be no longer free.

So What are the alternatives??

Many alternatives are available for Heroku in the market. Microsoft Azure, AWS and Digital Oceans are there with free tiers.  I am listing some of my favourite platforms below:-

Here is a github repo where you can find all the available free resources https://github.com/ripienaar/free-for-dev#ide-and-code-editing

Anvil

Anvil is a new way to build web apps, with nothing but Python. Anvil will be very helpful for your Data Science and other Python projects. The free tier of Anvil gives you a lifetime free development for unlimited apps.



Qoddi

Deploy your codes in seconds, with no infrastructure to manage. Qoddi offers a free platform for developers. You can migrate your apps from Heroku very easily with this documentation.


Appliku

Appliku is the next option with built in Django support and more. You can manage your workflow as simple as pushing code with git. 




Netlify 

Another powerful serverless platform with an intuitive git-based workflow. Netlify is a remote-first cloud computing company that offers a development platform that includes build, deploy, and serverless backend services for web applications and dynamic websites.


You can consider other options like AWS, Digital Ocean, Vultr, Vercel..etc. They offers some services for free or with a limited credit.



Share:

Monday, August 1, 2022

How to handle Exceptions in Java?

 

An exception is an event that disrupts the normal flow of the program. They are mainly two types:- Compile time and Runtime Exceptions. Compile time exceptions are checked at compile-time by the compiler. Runtime exceptions are thrown at runtime. Runtime errors occur while a program is running if the JVM detects an operation that is impossible to carry out. For example, if you access an array using an index that is out of bounds, you will get a runtime error with an ArrayIndexOutOfBoundsException. If you enter a string value when your program expects an integer, you will get a runtime error with an InputMismatchException.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import java.util.Scanner;

public class Exception {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        System.out.println("Enter a number");
        int num1= input.nextInt();

    }
}


Run the above code and enter a double value or string value as input:-





You can see an Exception has thrown due to the input mismatch. The Exception is pointed to a class called InputMismatchException. Like this there are several built in Exceptions in java.  


When an exception is thrown, the normal execution flow is interrupted. As the name suggests, to “throw an exception” is to pass the exception from one place to another. The statement for invoking the method is contained in a try block. The try block contains the  code that is executed in normal circumstances. The exception is caught by the catch block.The code in the catch block is executed to handle the exception. Afterward, the statement after the catch block is executed.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import java.util.InputMismatchException;
import java.util.Scanner;

public class Exception {
    public static void main(String[] args) {

        try {
            Scanner input = new Scanner(System.in);
            System.out.println("Enter a number");
            int num1 = input.nextInt();
        }

        catch (InputMismatchException e){
            System.out.println("Enter an integer number");

        }

    }
}

In the above code the exception is handled by a catch block (line no.13). InputMismatchException is a builtin class which don't need to be thrown by the user. 




Using "throw" keyword:-

The keyword throw is used to throw an exception. Later this exception is caught by the catch block. You can throw custom exception with the throw keyword. eg: throw new NotNumberException 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Scanner;

public class QuotientWithException {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        System.out.println("Enter first number: ");
        int num1 = input.nextInt();
        System.out.println("Enter first number: ");
        int num2 = input.nextInt();

        try {
            if(num2==0){
                throw new ArithmeticException("Division by zero");
            }
            double result = num1/num2;
            System.out.println("Result is "+result);
        }

        catch (ArithmeticException e){
            System.out.println(e+" exiting...");
        }
    }
}


On the line 13, an if condition is used to throw an Exception explicitly. Thereby we can add our message with the builtin one.

Output:-


"throw and throws"

Throw is used to throw an exception explicitly when throws is used as a method signature.



Throws is used to declare an exception which might get thrown by the method. Throws act as a warning which describes, the method may throw some exception.






Share: